Ingredients can now be manually ordered

This commit is contained in:
Greg Burri 2025-01-16 00:17:08 +01:00
parent afd42ba1d0
commit ca2227037f
11 changed files with 205 additions and 32 deletions

View file

@ -180,6 +180,25 @@ async fn check_user_rights_recipe_ingredient(
}
}
async fn check_user_rights_recipe_ingredients(
connection: &db::Connection,
user: &Option<model::User>,
step_ids: &[i64],
) -> Result<()> {
if user.is_none()
|| !connection
.can_edit_recipe_all_ingredients(user.as_ref().unwrap().id, step_ids)
.await?
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
}
}
#[debug_handler]
pub async fn set_recipe_title(
State(connection): State<db::Connection>,
@ -579,6 +598,19 @@ pub async fn set_ingredient_unit(
Ok(StatusCode::OK)
}
#[debug_handler]
pub async fn set_ingredients_order(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
ExtractRon(ron): ExtractRon<common::ron_api::SetIngredientOrders>,
) -> Result<impl IntoResponse> {
check_user_rights_recipe_ingredients(&connection, &user, &ron.ingredient_ids).await?;
connection
.set_ingredients_order(&ron.ingredient_ids)
.await?;
Ok(StatusCode::OK)
}
///// 404 /////
#[debug_handler]
pub async fn not_found(Extension(_user): Extension<Option<model::User>>) -> impl IntoResponse {