Rename active_schedule to override_schedule in request

This commit is contained in:
Tobias Reisinger 2024-05-26 22:47:13 +02:00
parent b28db015b4
commit 470b9c905b
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 26 additions and 15 deletions

View file

@ -6,7 +6,7 @@
"url": "https://git.serguzim.me/emgauwa/"
},
"title": "Emgauwa API v1",
"version": "0.5.1",
"version": "0.6.0",
"description": "Server API to manage an Emgauwa system."
},
"tags": [
@ -524,8 +524,10 @@
"name": {
"type": "string"
},
"active_schedule": {
"override_schedule": {
"type": "object",
"nullable": true,
"description": "NULL will remove the override schedule, missing field will not change the override schedule",
"properties": {
"id": {
"$ref": "#/components/schemas/schedule_id"
@ -1118,6 +1120,14 @@
"active_schedule": {
"$ref": "#/components/schemas/schedule_simple"
},
"override_schedule": {
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/schedule_simple"
}
]
},
"schedules": {
"type": "array",
"maxItems": 7,

View file

@ -6,7 +6,6 @@ use emgauwa_common::models::{convert_db_list, FromDbModel, Relay};
use emgauwa_common::types::{
ControllerWsAction, EmgauwaUid, RequestRelayPulse, RequestRelayUpdate,
};
use emgauwa_common::utils;
use sqlx::{Pool, Sqlite};
use crate::app_state;
@ -124,24 +123,26 @@ pub async fn update_for_controller(
}
}
if let Some(s_uid) = &data.active_schedule {
let schedule = s_uid.get_schedule(&mut pool_conn).await?;
DbJunctionRelaySchedule::set_schedule(
&mut pool_conn,
&relay,
&schedule,
utils::get_weekday(),
)
.await?;
}
if let Some(tags) = &data.tags {
relay.set_tags(&mut pool_conn, tags.as_slice()).await?;
}
let relay = relay.reload(&mut pool_conn).await?;
let return_relay = Relay::from_db_model(&mut pool_conn, relay)?;
let mut return_relay = Relay::from_db_model(&mut pool_conn, relay)?;
match &data.override_schedule {
Some(Some(s_uid)) => { // We want to set an override schedule
let schedule = s_uid.get_schedule(&mut pool_conn).await?;
return_relay.override_schedule = Some(Some(schedule));
}
Some(None) => { // We want to unset the override schedule
return_relay.override_schedule = Some(None);
}
None => { // We want to keep the override schedule as is
return_relay.override_schedule = None;
}
}
app_state
.send(app_state::Action {