Rename active_schedule to override_schedule in request
This commit is contained in:
parent
b28db015b4
commit
470b9c905b
2 changed files with 26 additions and 15 deletions
14
api.v1.json
14
api.v1.json
|
@ -6,7 +6,7 @@
|
||||||
"url": "https://git.serguzim.me/emgauwa/"
|
"url": "https://git.serguzim.me/emgauwa/"
|
||||||
},
|
},
|
||||||
"title": "Emgauwa API v1",
|
"title": "Emgauwa API v1",
|
||||||
"version": "0.5.1",
|
"version": "0.6.0",
|
||||||
"description": "Server API to manage an Emgauwa system."
|
"description": "Server API to manage an Emgauwa system."
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -524,8 +524,10 @@
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"active_schedule": {
|
"override_schedule": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"nullable": true,
|
||||||
|
"description": "NULL will remove the override schedule, missing field will not change the override schedule",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"$ref": "#/components/schemas/schedule_id"
|
"$ref": "#/components/schemas/schedule_id"
|
||||||
|
@ -1118,6 +1120,14 @@
|
||||||
"active_schedule": {
|
"active_schedule": {
|
||||||
"$ref": "#/components/schemas/schedule_simple"
|
"$ref": "#/components/schemas/schedule_simple"
|
||||||
},
|
},
|
||||||
|
"override_schedule": {
|
||||||
|
"nullable": true,
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/schedule_simple"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"schedules": {
|
"schedules": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"maxItems": 7,
|
"maxItems": 7,
|
||||||
|
|
|
@ -6,7 +6,6 @@ use emgauwa_common::models::{convert_db_list, FromDbModel, Relay};
|
||||||
use emgauwa_common::types::{
|
use emgauwa_common::types::{
|
||||||
ControllerWsAction, EmgauwaUid, RequestRelayPulse, RequestRelayUpdate,
|
ControllerWsAction, EmgauwaUid, RequestRelayPulse, RequestRelayUpdate,
|
||||||
};
|
};
|
||||||
use emgauwa_common::utils;
|
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
use crate::app_state;
|
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 {
|
if let Some(tags) = &data.tags {
|
||||||
relay.set_tags(&mut pool_conn, tags.as_slice()).await?;
|
relay.set_tags(&mut pool_conn, tags.as_slice()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let relay = relay.reload(&mut pool_conn).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
|
app_state
|
||||||
.send(app_state::Action {
|
.send(app_state::Action {
|
||||||
|
|
Loading…
Reference in a new issue