use super::logic;
use crate::error::{run_blocking, AppError};
use axum::{
extract::{Path, State},
Json,
};
use logic::{RoutineResponse, RoutineStore, UpdateRoutineRequest};
#[utoipa::path(patch, path = "/routines/{id}",
params(("id" = String, Path, description = "Routine UUID")),
request_body = UpdateRoutineRequest,
responses((status = 200, body = RoutineResponse), (status = 400, description = "Invalid"), (status = 404, description = "Not found")))]
pub async fn update_routine(
State(store): State<RoutineStore>,
Path(id): Path<String>,
Json(body): Json<UpdateRoutineRequest>,
) -> Result<Json<RoutineResponse>, AppError> {
let resp = run_blocking(move || logic::build(&store, &id, body)).await?;
Ok(Json(resp))
}
#[utoipa::path(put, path = "/routines/{id}",
params(("id" = String, Path, description = "Routine UUID")),
request_body = UpdateRoutineRequest,
responses((status = 200, body = RoutineResponse), (status = 400, description = "Invalid"), (status = 404, description = "Not found")))]
pub async fn replace(
state: State<RoutineStore>,
path: Path<String>,
body: Json<UpdateRoutineRequest>,
) -> Result<Json<RoutineResponse>, AppError> {
update_routine(state, path, body).await
}
#[cfg(test)]
#[path = "http_tests.rs"]
mod http_tests;