Skip to content

Commit

Permalink
allow string type open states
Browse files Browse the repository at this point in the history
  • Loading branch information
gueldenstone committed May 11, 2024
1 parent f8a5a86 commit 14cbbea
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub async fn get_status(app_state: Data<AppState>) -> Result<Json<Status>> {
#[derive(Debug, Deserialize)]
struct StateData {
open: Option<bool>,
open_string: Option<String>,
message: Option<String>,
}

Expand All @@ -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::<bool>()
.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")))
Expand Down

0 comments on commit 14cbbea

Please sign in to comment.