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
|
|
@ -86,6 +86,7 @@ pub struct EditIngredientRequest {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct CreateRecipeRequest {
|
pub struct CreateRecipeRequest {
|
||||||
|
pub person_count: u32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub rating: u8,
|
pub rating: u8,
|
||||||
pub ingredients: Vec<(i64, f64)>,
|
pub ingredients: Vec<(i64, f64)>,
|
||||||
|
|
@ -106,6 +107,7 @@ pub struct ListRecipesResponse {
|
||||||
pub struct RecipeInfo {
|
pub struct RecipeInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub rating: u8,
|
pub rating: u8,
|
||||||
|
pub person_count: u32,
|
||||||
pub steps: String,
|
pub steps: String,
|
||||||
pub ingredients: Vec<(i64, IngredientInfo, f64)>,
|
pub ingredients: Vec<(i64, IngredientInfo, f64)>,
|
||||||
}
|
}
|
||||||
|
|
@ -134,3 +136,8 @@ pub struct RecipeEditStepsRequest {
|
||||||
pub struct RecipeEditRating {
|
pub struct RecipeEditRating {
|
||||||
pub rating: u8,
|
pub rating: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub struct RecipeEditPersonCount {
|
||||||
|
pub person_count: u32,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -357,6 +357,7 @@ pub fn RecipeCreator() -> Html {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|rcp_ig: &RecipeIngredient| (rcp_ig.id, rcp_ig.amount / (*pc) as f64))
|
.map(|rcp_ig: &RecipeIngredient| (rcp_ig.id, rcp_ig.amount / (*pc) as f64))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
person_count: (*pc) as _,
|
||||||
steps: (*s).clone(),
|
steps: (*s).clone(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,10 @@ pub(crate) fn router(api_allowed: Option<HeaderValue>) -> Router<AppState> {
|
||||||
"/household/:house_id/recipe/:recipe_id/rating",
|
"/household/:house_id/recipe/:recipe_id/rating",
|
||||||
patch(recipe::edit_rating).layer(mk_service(vec![Method::PATCH])),
|
patch(recipe::edit_rating).layer(mk_service(vec![Method::PATCH])),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/household/:house_id/recipe/:recipe_id/person_count",
|
||||||
|
patch(recipe::edit_person_count).layer(mk_service(vec![Method::PATCH])),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/household/:house_id/recipe/:recipe_id/ingredients/:iid",
|
"/household/:house_id/recipe/:recipe_id/ingredients/:iid",
|
||||||
patch(recipe::edit_ig_amount)
|
patch(recipe::edit_ig_amount)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use api::{
|
use api::{
|
||||||
AddRecipeIngredientRequest, CreateRecipeRequest, CreateRecipeResponse, EmptyResponse,
|
AddRecipeIngredientRequest, CreateRecipeRequest, CreateRecipeResponse, EmptyResponse,
|
||||||
IngredientInfo, ListRecipesResponse, RecipeEditRating, RecipeEditStepsRequest, RecipeInfo,
|
IngredientInfo, ListRecipesResponse, RecipeEditRating, RecipeEditStepsRequest, RecipeInfo,
|
||||||
RecipeIngredientEditRequest, RecipeRenameRequest,
|
RecipeIngredientEditRequest, RecipeRenameRequest, RecipeEditPersonCount,
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
async_trait,
|
async_trait,
|
||||||
|
|
@ -32,6 +32,7 @@ pub(super) async fn create_recipe(
|
||||||
ranking: ActiveValue::Set(request.rating as i32),
|
ranking: ActiveValue::Set(request.rating as i32),
|
||||||
household: ActiveValue::Set(household.id),
|
household: ActiveValue::Set(household.id),
|
||||||
steps: ActiveValue::Set(request.steps),
|
steps: ActiveValue::Set(request.steps),
|
||||||
|
person_count: ActiveValue::Set(request.person_count.min(1) as i32),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -142,6 +143,7 @@ pub(super) async fn fetch_recipe(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RecipeInfo {
|
Ok(RecipeInfo {
|
||||||
|
person_count: recipe.person_count as _,
|
||||||
name: recipe.name,
|
name: recipe.name,
|
||||||
steps: recipe.steps,
|
steps: recipe.steps,
|
||||||
rating: recipe.ranking as _,
|
rating: recipe.ranking as _,
|
||||||
|
|
@ -243,3 +245,19 @@ pub(super) async fn edit_rating(
|
||||||
|
|
||||||
Ok(EmptyResponse {}.into())
|
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