app,server: Allow to edit the rating

This commit is contained in:
traxys 2023-06-26 12:47:06 +02:00
parent 5ef000dec0
commit d614029931
4 changed files with 167 additions and 15 deletions

View file

@ -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())
}