Recipe can now be scheduled

This commit is contained in:
Greg Burri 2025-02-04 22:29:56 +01:00
parent ae6da1a5ae
commit fbef990022
18 changed files with 233 additions and 51 deletions

View file

@ -631,6 +631,36 @@ pub async fn get_scheduled_recipes(
}
}
#[debug_handler]
pub async fn schedule_recipe(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
ExtractRon(ron): ExtractRon<common::ron_api::ScheduleRecipe>,
) -> Result<impl IntoResponse> {
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
if let Some(user) = user {
connection
.add_scheduled_recipe(user.id, ron.recipe_id, ron.date, ron.servings)
.await?;
}
Ok(StatusCode::OK)
}
#[debug_handler]
pub async fn rm_scheduled_recipe(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
ExtractRon(ron): ExtractRon<common::ron_api::ScheduledRecipe>,
) -> Result<impl IntoResponse> {
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
if let Some(user) = user {
connection
.rm_scheduled_recipe(user.id, ron.recipe_id, ron.date)
.await?;
}
Ok(StatusCode::OK)
}
/// 404 ///
#[debug_handler]