Format code a bit

This commit is contained in:
Tobias Reisinger 2024-05-23 20:18:11 +02:00
parent d76bf0f711
commit b28db015b4
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
6 changed files with 24 additions and 17 deletions

BIN
Cargo.lock generated

Binary file not shown.

View file

@ -1,14 +1,15 @@
use actix::Addr; use actix::Addr;
use actix_web::{delete, get, HttpResponse, post, put, web}; use actix_web::{delete, get, post, put, web, HttpResponse};
use sqlx::{Pool, Sqlite};
use sqlx::pool::PoolConnection;
use emgauwa_common::db::{DbController, DbMacro}; use emgauwa_common::db::{DbController, DbMacro};
use emgauwa_common::errors::{DatabaseError, EmgauwaError}; use emgauwa_common::errors::{DatabaseError, EmgauwaError};
use emgauwa_common::models::{convert_db_list, FromDbModel, Macro, MacroAction, Relay}; use emgauwa_common::models::{convert_db_list, FromDbModel, Macro, MacroAction, Relay};
use emgauwa_common::types::{ControllerWsAction, EmgauwaUid, RequestMacroCreate, RequestMacroExecute, RequestMacroUpdate}; use emgauwa_common::types::{
use crate::app_state; ControllerWsAction, EmgauwaUid, RequestMacroCreate, RequestMacroExecute, RequestMacroUpdate,
};
use sqlx::pool::PoolConnection;
use sqlx::{Pool, Sqlite};
use crate::app_state;
use crate::app_state::AppState; use crate::app_state::AppState;
use crate::handlers::EmgauwaMessage; use crate::handlers::EmgauwaMessage;
@ -133,8 +134,8 @@ pub async fn execute(
let affected_controllers = collect_affected_controllers(&mut pool_conn, &actions).await?; let affected_controllers = collect_affected_controllers(&mut pool_conn, &actions).await?;
for controller in affected_controllers { for controller in affected_controllers {
let affected_relays =
let affected_relays = collect_affected_relays(&mut pool_conn, &mut actions, &controller).await?; collect_affected_relays(&mut pool_conn, &mut actions, &controller).await?;
app_state app_state
.send(app_state::Action { .send(app_state::Action {
@ -159,10 +160,11 @@ async fn collect_affected_controllers(
.iter() .iter()
.any(|controller| controller.id == controller_id) .any(|controller| controller.id == controller_id)
{ {
continue continue;
} }
let controller = DbController::get(pool_conn, controller_id).await? let controller = DbController::get(pool_conn, controller_id)
.await?
.ok_or(DatabaseError::NotFound)?; .ok_or(DatabaseError::NotFound)?;
affected_controllers.push(controller); affected_controllers.push(controller);
} }
@ -177,7 +179,9 @@ async fn collect_affected_relays(
let mut affected_relays: Vec<Relay> = Vec::new(); let mut affected_relays: Vec<Relay> = Vec::new();
for action in actions { for action in actions {
if affected_relays.iter().any(|relay| relay.r.id == action.relay.r.id) if affected_relays
.iter()
.any(|relay| relay.r.id == action.relay.r.id)
|| action.relay.r.controller_id != controller.id || action.relay.r.controller_id != controller.id
{ {
continue; continue;

View file

@ -3,7 +3,10 @@ use actix_web::{delete, get, post, put, web, HttpResponse};
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbSchedule, DbTag}; use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbSchedule, DbTag};
use emgauwa_common::errors::{ApiError, DatabaseError, EmgauwaError}; use emgauwa_common::errors::{ApiError, DatabaseError, EmgauwaError};
use emgauwa_common::models::{convert_db_list, FromDbModel, Schedule}; use emgauwa_common::models::{convert_db_list, FromDbModel, Schedule};
use emgauwa_common::types::{ControllerWsAction, RequestScheduleCreate, RequestScheduleGetTagged, RequestScheduleUpdate, ScheduleUid}; use emgauwa_common::types::{
ControllerWsAction, RequestScheduleCreate, RequestScheduleGetTagged, RequestScheduleUpdate,
ScheduleUid,
};
use itertools::Itertools; use itertools::Itertools;
use sqlx::pool::PoolConnection; use sqlx::pool::PoolConnection;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};

View file

@ -4,6 +4,7 @@ use emgauwa_common::errors::{DatabaseError, EmgauwaError};
use emgauwa_common::models::{FromDbModel, Tag}; use emgauwa_common::models::{FromDbModel, Tag};
use emgauwa_common::types::RequestTagCreate; use emgauwa_common::types::RequestTagCreate;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use crate::handlers::EmgauwaMessage; use crate::handlers::EmgauwaMessage;
#[get("/tags")] #[get("/tags")]

View file

@ -4,12 +4,11 @@ use actix::{Actor, Arbiter};
use actix_cors::Cors; use actix_cors::Cors;
use actix_web::middleware::TrailingSlash; use actix_web::middleware::TrailingSlash;
use actix_web::{middleware, web, App, HttpServer}; use actix_web::{middleware, web, App, HttpServer};
use serde_json::Value;
use utoipa_swagger_ui::SwaggerUi;
use emgauwa_common::db::DbController; use emgauwa_common::db::DbController;
use emgauwa_common::errors::EmgauwaError; use emgauwa_common::errors::EmgauwaError;
use emgauwa_common::utils::{drop_privileges, init_logging}; use emgauwa_common::utils::{drop_privileges, init_logging};
use serde_json::Value;
use utoipa_swagger_ui::SwaggerUi;
use crate::app_state::AppState; use crate::app_state::AppState;