implementing get endpoint for alarms wip
This commit is contained in:
@@ -1,32 +1,49 @@
|
||||
use axum::{Json, http::StatusCode, response::IntoResponse};
|
||||
use axum::{Json, debug_handler, extract::Query, http::StatusCode, response::IntoResponse};
|
||||
use chrono::{DateTime, Local};
|
||||
use utoipa::{IntoResponses, ToSchema};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::{IntoParams, IntoResponses, ToSchema};
|
||||
|
||||
#[derive(ToSchema)]
|
||||
struct OkResponse {
|
||||
name: String,
|
||||
enabled: bool,
|
||||
time: DateTime<Local>
|
||||
#[derive(ToSchema, Serialize)]
|
||||
pub struct OkResponse {
|
||||
name: String,
|
||||
enabled: bool,
|
||||
time: DateTime<Local>,
|
||||
}
|
||||
|
||||
#[derive(IntoResponses)]
|
||||
enum Responses {
|
||||
#[response(status = 200)]
|
||||
Ok(#[to_schema] Vec<OkResponse>),
|
||||
#[response(status = 500)]
|
||||
DBError(String)
|
||||
pub enum Responses {
|
||||
#[response(status = 200)]
|
||||
Ok(#[to_schema] Vec<OkResponse>),
|
||||
#[response(status = 500)]
|
||||
DBError(String),
|
||||
}
|
||||
|
||||
impl IntoResponse for Responses {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
Responses::Ok(body) => (StatusCode::OK, Json(body)).into_response(),
|
||||
Responses::DBError(message) => (StatusCode::INTERNAL_SERVER_ERROR, Json(message)).into_response(),
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
Responses::Ok(body) => (StatusCode::OK, Json(body)).into_response(),
|
||||
Responses::DBError(message) => {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(message)).into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoParams, Deserialize)]
|
||||
pub struct RequestQuery {
|
||||
enabled: Option<bool>
|
||||
}
|
||||
|
||||
#[utoipa::path(get, path = "", responses(Responses), params(RequestQuery))]
|
||||
#[debug_handler]
|
||||
pub async fn get_handler(Query(RequestQuery { enabled }): Query<RequestQuery>) -> Responses {
|
||||
match enabled {
|
||||
Some(enabled) => {
|
||||
let alarms = crate::db::alarm::get_alarms(enabled).await;
|
||||
todo!()
|
||||
},
|
||||
None => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn get_handler() -> Responses {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user