app,server: Allow to edit the rating
This commit is contained in:
parent
5ef000dec0
commit
d614029931
4 changed files with 167 additions and 15 deletions
|
|
@ -232,6 +232,10 @@ pub(crate) fn router(api_allowed: Option<HeaderValue>) -> Router<AppState> {
|
|||
"/household/:house_id/recipe/:recipe_id/steps",
|
||||
patch(recipe::edit_step).layer(mk_service(vec![Method::PATCH])),
|
||||
)
|
||||
.route(
|
||||
"/household/:house_id/recipe/:recipe_id/rating",
|
||||
patch(recipe::edit_rating).layer(mk_service(vec![Method::PATCH])),
|
||||
)
|
||||
.route(
|
||||
"/household/:house_id/recipe/:recipe_id/ingredients/:iid",
|
||||
patch(recipe::edit_ig_amount)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use api::{
|
||||
AddRecipeIngredientRequest, CreateRecipeRequest, CreateRecipeResponse, EmptyResponse,
|
||||
IngredientInfo, ListRecipesResponse, RecipeEditStepsRequest, RecipeInfo,
|
||||
IngredientInfo, ListRecipesResponse, RecipeEditRating, RecipeEditStepsRequest, RecipeInfo,
|
||||
RecipeIngredientEditRequest, RecipeRenameRequest,
|
||||
};
|
||||
use axum::{
|
||||
|
|
@ -227,3 +227,19 @@ pub(super) async fn edit_step(
|
|||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
||||
pub(super) async fn edit_rating(
|
||||
State(state): State<AppState>,
|
||||
RecipeExtractor(recipe): RecipeExtractor,
|
||||
Json(req): Json<RecipeEditRating>,
|
||||
) -> JsonResult<EmptyResponse> {
|
||||
let model = recipe::ActiveModel {
|
||||
id: ActiveValue::Set(recipe.id),
|
||||
ranking: ActiveValue::Set(req.rating as _),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
model.update(&state.db).await?;
|
||||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue