Factorize some ron api types
This commit is contained in:
parent
ca2227037f
commit
67e13d9074
3 changed files with 62 additions and 211 deletions
|
|
@ -346,10 +346,10 @@ pub async fn set_is_published(
|
|||
pub async fn rm(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Remove>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
connection.rm_recipe(ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &user, ron.id).await?;
|
||||
connection.rm_recipe(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -415,25 +415,22 @@ pub async fn get_groups(
|
|||
pub async fn add_group(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeGroup>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
let group_id = connection.add_recipe_group(ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &user, ron.id).await?;
|
||||
let id = connection.add_recipe_group(ron.id).await?;
|
||||
|
||||
Ok(ron_response(
|
||||
StatusCode::OK,
|
||||
common::ron_api::AddRecipeGroupResult { group_id },
|
||||
))
|
||||
Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn rm_group(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeGroup>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
|
||||
connection.rm_recipe_group(ron.group_id).await?;
|
||||
check_user_rights_recipe_group(&connection, &user, ron.id).await?;
|
||||
connection.rm_recipe_group(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -465,10 +462,10 @@ pub async fn set_group_comment(
|
|||
pub async fn set_groups_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetGroupOrders>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_groups(&connection, &user, &ron.group_ids).await?;
|
||||
connection.set_groups_order(&ron.group_ids).await?;
|
||||
check_user_rights_recipe_groups(&connection, &user, &ron.ids).await?;
|
||||
connection.set_groups_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -476,25 +473,22 @@ pub async fn set_groups_order(
|
|||
pub async fn add_step(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeStep>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
|
||||
let step_id = connection.add_recipe_step(ron.group_id).await?;
|
||||
check_user_rights_recipe_group(&connection, &user, ron.id).await?;
|
||||
let id = connection.add_recipe_step(ron.id).await?;
|
||||
|
||||
Ok(ron_response(
|
||||
StatusCode::OK,
|
||||
common::ron_api::AddRecipeStepResult { step_id },
|
||||
))
|
||||
Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn rm_step(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeStep>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_step(&connection, &user, ron.step_id).await?;
|
||||
connection.rm_recipe_step(ron.step_id).await?;
|
||||
check_user_rights_recipe_step(&connection, &user, ron.id).await?;
|
||||
connection.rm_recipe_step(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -513,10 +507,10 @@ pub async fn set_step_action(
|
|||
pub async fn set_steps_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetStepOrders>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_steps(&connection, &user, &ron.step_ids).await?;
|
||||
connection.set_steps_order(&ron.step_ids).await?;
|
||||
check_user_rights_recipe_steps(&connection, &user, &ron.ids).await?;
|
||||
connection.set_steps_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -524,25 +518,22 @@ pub async fn set_steps_order(
|
|||
pub async fn add_ingredient(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeIngredient>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_step(&connection, &user, ron.step_id).await?;
|
||||
let ingredient_id = connection.add_recipe_ingredient(ron.step_id).await?;
|
||||
check_user_rights_recipe_step(&connection, &user, ron.id).await?;
|
||||
let id = connection.add_recipe_ingredient(ron.id).await?;
|
||||
|
||||
Ok(ron_response(
|
||||
StatusCode::OK,
|
||||
common::ron_api::AddRecipeIngredientResult { ingredient_id },
|
||||
))
|
||||
Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn rm_ingredient(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeIngredient>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
|
||||
connection.rm_recipe_ingredient(ron.ingredient_id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.id).await?;
|
||||
connection.rm_recipe_ingredient(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
@ -602,12 +593,10 @@ pub async fn set_ingredient_unit(
|
|||
pub async fn set_ingredients_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetIngredientOrders>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredients(&connection, &user, &ron.ingredient_ids).await?;
|
||||
connection
|
||||
.set_ingredients_order(&ron.ingredient_ids)
|
||||
.await?;
|
||||
check_user_rights_recipe_ingredients(&connection, &user, &ron.ids).await?;
|
||||
connection.set_ingredients_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue