app,server: Allow to set the person count when creating a recipe
This commit is contained in:
parent
614ff07552
commit
8987991139
4 changed files with 31 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use api::{
|
||||
AddRecipeIngredientRequest, CreateRecipeRequest, CreateRecipeResponse, EmptyResponse,
|
||||
IngredientInfo, ListRecipesResponse, RecipeEditRating, RecipeEditStepsRequest, RecipeInfo,
|
||||
RecipeIngredientEditRequest, RecipeRenameRequest,
|
||||
RecipeIngredientEditRequest, RecipeRenameRequest, RecipeEditPersonCount,
|
||||
};
|
||||
use axum::{
|
||||
async_trait,
|
||||
|
|
@ -32,6 +32,7 @@ pub(super) async fn create_recipe(
|
|||
ranking: ActiveValue::Set(request.rating as i32),
|
||||
household: ActiveValue::Set(household.id),
|
||||
steps: ActiveValue::Set(request.steps),
|
||||
person_count: ActiveValue::Set(request.person_count.min(1) as i32),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
@ -142,6 +143,7 @@ pub(super) async fn fetch_recipe(
|
|||
}
|
||||
|
||||
Ok(RecipeInfo {
|
||||
person_count: recipe.person_count as _,
|
||||
name: recipe.name,
|
||||
steps: recipe.steps,
|
||||
rating: recipe.ranking as _,
|
||||
|
|
@ -243,3 +245,19 @@ pub(super) async fn edit_rating(
|
|||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
||||
pub(super) async fn edit_person_count(
|
||||
State(state): State<AppState>,
|
||||
RecipeExtractor(recipe): RecipeExtractor,
|
||||
Json(req): Json<RecipeEditPersonCount>,
|
||||
) -> JsonResult<EmptyResponse> {
|
||||
let model = recipe::ActiveModel {
|
||||
id: ActiveValue::Set(recipe.id),
|
||||
person_count: ActiveValue::Set(req.person_count.min(1) as _),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
model.update(&state.db).await?;
|
||||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue