removed some deps, using heap to store the current ringer (makes it more dynamic)
This commit is contained in:
@@ -4,14 +4,13 @@ use axum::http::StatusCode;
|
||||
use axum::debug_handler;
|
||||
use axum::response::IntoResponse;
|
||||
use chrono::{DateTime, Local};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::{IntoResponses, ToSchema};
|
||||
|
||||
use crate::AppState;
|
||||
use crate::types::Alarm;
|
||||
|
||||
#[derive(Debug, Deserialize, JsonSchema, ToSchema)]
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct RequestBody {
|
||||
time: DateTime<Local>,
|
||||
}
|
||||
@@ -55,6 +54,14 @@ impl From<Alarm> for OkResponseBody {
|
||||
)]
|
||||
#[debug_handler]
|
||||
pub async fn post_handler(State(AppState { scheduler, ..}): State<AppState>, Json(body): Json<RequestBody>) -> Responses {
|
||||
let alarm = scheduler.add_alarm(body.time).await.unwrap();
|
||||
Responses::Ok(alarm.into())
|
||||
let result = scheduler.add_alarm(body.time).await;
|
||||
|
||||
match result {
|
||||
Ok(alarm) => {
|
||||
Responses::Ok(alarm.into())
|
||||
},
|
||||
Err(e) => {
|
||||
Responses::Error(e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user