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 134 additions and 25 deletions
src/handlers/v1

View file

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