From 14cbbeabbcd7a30580ad50ff4738c792782690cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Gu=CC=88ldenstein?= Date: Sun, 12 May 2024 01:15:33 +0200 Subject: [PATCH] allow string type open states --- src/api/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index dd73198..c2c80d9 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -18,6 +18,7 @@ pub async fn get_status(app_state: Data) -> Result> { #[derive(Debug, Deserialize)] struct StateData { open: Option, + open_string: Option, message: Option, } @@ -39,7 +40,23 @@ pub async fn set_state( None => &mut default_state, Some(state) => state, }; - state.open = new_state_data.open; + state.open = match new_state_data.open { + None => { + // try to parse the string version + let parsed_open = new_state_data + .open_string + .to_owned() + .unwrap() + .parse::() + .map_err(|err| AppError { + message: None, + cause: Some(err.to_string()), + error_type: AppErrorType::InternalError, + }); + Some(parsed_open.unwrap()) + } + Some(open) => Some(open), + }; state.message.clone_from(&new_state_data.message); status.state = Some(state.to_owned()); Ok(Json(String::from("Success")))