From a17a9868faeb4a10fed59f5375795cdded8db18c Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 21 Nov 2023 14:58:01 +0100 Subject: [PATCH] Reformat code --- api.v1.yaml | 44 ++++++++++++++++++------------------ src/db/model_utils.rs | 3 ++- src/db/models.rs | 2 +- src/db/tag.rs | 8 ++++--- src/handlers/v1/schedules.rs | 7 +++--- src/main.rs | 3 ++- src/settings.rs | 3 ++- src/types/emgauwa_uid.rs | 3 ++- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/api.v1.yaml b/api.v1.yaml index 021da3e..b662914 100644 --- a/api.v1.yaml +++ b/api.v1.yaml @@ -26,7 +26,7 @@ paths: responses: '200': description: OK - headers: {} + headers: { } content: application/json: schema: @@ -53,7 +53,7 @@ paths: schema: $ref: '#/components/schemas/schedule' description: The "id" field will be set by the server. - parameters: [] + parameters: [ ] '/api/v1/schedules/{schedule_id}': parameters: - schema: @@ -80,7 +80,7 @@ paths: application/json: schema: type: object - properties: {} + properties: { } operationId: get-schedules-schedule_id description: Return a single schedule by id. put: @@ -100,14 +100,14 @@ paths: application/json: schema: type: object - properties: {} + properties: { } '404': description: Not Found content: application/json: schema: type: object - properties: {} + properties: { } operationId: put-schedules-schedule_id requestBody: content: @@ -126,7 +126,7 @@ paths: items: $ref: '#/components/schemas/tag' description: '' - parameters: [] + parameters: [ ] description: Overwrite the properties for a single schedule. Overwriting periods on "on" or "off" will fail. delete: summary: delete single schedule @@ -172,7 +172,7 @@ paths: responses: '200': description: OK - headers: {} + headers: { } content: application/json: schema: @@ -181,7 +181,7 @@ paths: $ref: '#/components/schemas/relay' operationId: get-relays description: Return a list with all relays. - parameters: [] + parameters: [ ] '/api/v1/relays/tag/{tag}': parameters: - schema: @@ -218,7 +218,7 @@ paths: $ref: '#/components/schemas/controller' operationId: get-controllers description: Return all controllers. - parameters: [] + parameters: [ ] /api/v1/controllers/discover: put: summary: discover controllers @@ -235,7 +235,7 @@ paths: $ref: '#/components/schemas/controller' operationId: put-controllers-discover description: Start a discovery process to find controllers in the network. This operations needs multiple seconds to complete. - parameters: [] + parameters: [ ] '/api/v1/controllers/{controller_id}': parameters: - schema: @@ -261,14 +261,14 @@ paths: application/json: schema: type: object - properties: {} + properties: { } operationId: get-controllers-controller_id requestBody: content: application/json: schema: type: object - properties: {} + properties: { } description: '' description: Return a single controller by id. When no controller with the id is found 404 will be returned. put: @@ -288,14 +288,14 @@ paths: application/json: schema: type: object - properties: {} + properties: { } '404': description: Not Found content: application/json: schema: type: object - properties: {} + properties: { } operationId: put-controllers-controller_id requestBody: content: @@ -335,7 +335,7 @@ paths: responses: '200': description: OK - headers: {} + headers: { } content: application/json: schema: @@ -348,7 +348,7 @@ paths: application/json: schema: type: array - items: {} + items: { } operationId: get-controllers-controller_id-relays description: Returns all relays for a single controller. '/api/v1/controllers/{controller_id}/relays/{relay_num}': @@ -381,7 +381,7 @@ paths: application/json: schema: type: object - properties: {} + properties: { } operationId: get-controllers-controller_id-relays-relay_num description: 'Return a single relay by number for a controller by id. When the relay or controller is not found, 404 will be returned.' put: @@ -402,14 +402,14 @@ paths: application/json: schema: type: object - properties: {} + properties: { } '404': description: Not Found content: application/json: schema: type: object - properties: {} + properties: { } operationId: put-controllers-controller_id-relays-relay_num requestBody: content: @@ -454,7 +454,7 @@ paths: $ref: '#/components/schemas/tag' operationId: get-tags description: Returns a list of tags. - parameters: [] + parameters: [ ] post: summary: add new tag operationId: post-api-v1-tags @@ -568,7 +568,7 @@ paths: description: |- WEBSOCKET This websocket will send all relays with the most recent status every 10 seconds. - parameters: [] + parameters: [ ] /api/v1/macros: get: summary: get all macros @@ -723,7 +723,7 @@ paths: items: $ref: '#/components/schemas/schedule' description: Create a list of schedules - parameters: [] + parameters: [ ] components: schemas: controller: diff --git a/src/db/model_utils.rs b/src/db/model_utils.rs index 998025f..8ec71c7 100644 --- a/src/db/model_utils.rs +++ b/src/db/model_utils.rs @@ -1,4 +1,3 @@ -use crate::db::models::Periods; use chrono::{NaiveTime, Timelike}; use serde::{Deserialize, Serialize}; use sqlx::database::HasArguments; @@ -7,6 +6,8 @@ use sqlx::error::BoxDynError; use sqlx::sqlite::{SqliteTypeInfo, SqliteValueRef}; use sqlx::{Decode, Encode, Sqlite, Type}; +use crate::db::models::Periods; + #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] pub struct Period { #[serde(with = "period_format")] diff --git a/src/db/models.rs b/src/db/models.rs index 4b1c99d..d783925 100644 --- a/src/db/models.rs +++ b/src/db/models.rs @@ -1,6 +1,6 @@ -use crate::db::model_utils::Period; use serde::{Deserialize, Serialize}; +use crate::db::model_utils::Period; use crate::types::EmgauwaUid; #[derive(Debug, Serialize)] diff --git a/src/db/tag.rs b/src/db/tag.rs index 556eb0c..dc3cc16 100644 --- a/src/db/tag.rs +++ b/src/db/tag.rs @@ -1,8 +1,10 @@ -use crate::db::errors::DatabaseError; -use crate::db::models::*; +use std::ops::DerefMut; + use sqlx::pool::PoolConnection; use sqlx::Sqlite; -use std::ops::DerefMut; + +use crate::db::errors::DatabaseError; +use crate::db::models::*; pub async fn create_tag( conn: &mut PoolConnection, diff --git a/src/handlers/v1/schedules.rs b/src/handlers/v1/schedules.rs index fc054d6..594ec7e 100644 --- a/src/handlers/v1/schedules.rs +++ b/src/handlers/v1/schedules.rs @@ -1,11 +1,12 @@ -use crate::db::errors::DatabaseError; +use std::borrow::Borrow; +use std::convert::TryFrom; + use actix_web::{delete, get, post, put, web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; use sqlx::pool::PoolConnection; use sqlx::{Pool, Sqlite}; -use std::borrow::Borrow; -use std::convert::TryFrom; +use crate::db::errors::DatabaseError; use crate::db::models::{Periods, Schedule}; use crate::db::schedules::*; use crate::db::tag::get_tag; diff --git a/src/main.rs b/src/main.rs index 8d3f292..03eeb33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ extern crate dotenv; +use std::str::FromStr; + use actix_web::middleware::TrailingSlash; use actix_web::{middleware, web, App, HttpServer}; use log::{trace, LevelFilter}; use simple_logger::SimpleLogger; -use std::str::FromStr; mod db; mod handlers; diff --git a/src/settings.rs b/src/settings.rs index fbb3d6c..ccfa057 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,7 +1,8 @@ +use std::sync::RwLock; + use config::Config; use lazy_static::lazy_static; use serde_derive::Deserialize; -use std::sync::RwLock; #[derive(Clone, Debug, Deserialize)] #[serde(default)] diff --git a/src/types/emgauwa_uid.rs b/src/types/emgauwa_uid.rs index ca96fe4..67ef58e 100644 --- a/src/types/emgauwa_uid.rs +++ b/src/types/emgauwa_uid.rs @@ -2,7 +2,6 @@ use std::convert::TryFrom; use std::fmt::{Debug, Formatter}; use std::str::FromStr; -use crate::types::EmgauwaUid; use serde::{Serialize, Serializer}; use sqlx::database::HasArguments; use sqlx::encode::IsNull; @@ -11,6 +10,8 @@ use sqlx::sqlite::{SqliteTypeInfo, SqliteValueRef}; use sqlx::{Decode, Encode, Sqlite, Type}; use uuid::Uuid; +use crate::types::EmgauwaUid; + impl EmgauwaUid { const OFF_STR: &'static str = "off"; const ON_STR: &'static str = "on";