Simplify schedule in macro action

This commit is contained in:
Tobias Reisinger 2024-05-13 19:17:35 +02:00
parent f26e66d687
commit 9326b66007
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -3,13 +3,13 @@ use serde_derive::{Deserialize, Serialize};
use sqlx::pool::PoolConnection;
use sqlx::Sqlite;
use crate::db::{DbJunctionRelaySchedule, DbMacroAction};
use crate::db::{DbJunctionRelaySchedule, DbMacroAction, DbSchedule};
use crate::errors::{DatabaseError, EmgauwaError};
use crate::models::{FromDbModel, Relay, Schedule};
use crate::models::{FromDbModel, Relay};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MacroAction {
pub schedule: Schedule,
pub schedule: DbSchedule,
pub relay: Relay,
pub weekday: i64,
}
@ -30,8 +30,7 @@ impl FromDbModel for MacroAction {
db_model: Self::DbModel,
_cache: Self::DbModelCache,
) -> Result<Self, DatabaseError> {
let schedule_db = block_on(db_model.get_schedule(conn))?;
let schedule = Schedule::from_db_model(conn, schedule_db)?;
let schedule = block_on(db_model.get_schedule(conn))?;
let relay_db = block_on(db_model.get_relay(conn))?;
let relay = Relay::from_db_model(conn, relay_db)?;
@ -48,7 +47,7 @@ impl FromDbModel for MacroAction {
impl MacroAction {
pub async fn execute(&self, conn: &mut PoolConnection<Sqlite>) -> Result<(), EmgauwaError> {
DbJunctionRelaySchedule::set_schedule(conn, &self.relay.r, &self.schedule.s, self.weekday)
DbJunctionRelaySchedule::set_schedule(conn, &self.relay.r, &self.schedule, self.weekday)
.await?;
Ok(())
}