app,server: Allow to add ingredients to existing recipes
This commit is contained in:
parent
6004520fb9
commit
27f9295aa3
5 changed files with 319 additions and 69 deletions
|
|
@ -232,6 +232,7 @@ pub(crate) fn router(api_allowed: Option<HeaderValue>) -> Router<AppState> {
|
|||
"/household/:house_id/recipe/:recipe_id/ingredients/:iid",
|
||||
patch(recipe::edit_ig_amount)
|
||||
.delete(recipe::delete_ig)
|
||||
.layer(mk_service(vec![Method::PATCH, Method::DELETE])),
|
||||
.put(recipe::add_ig_request)
|
||||
.layer(mk_service(vec![Method::PATCH, Method::DELETE, Method::PUT])),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use api::{
|
||||
CreateRecipeRequest, CreateRecipeResponse, EmptyResponse, IngredientInfo, ListRecipesResponse,
|
||||
RecipeInfo, RecipeIngredientEditRequest, RecipeRenameRequest,
|
||||
AddRecipeIngredientRequest, CreateRecipeRequest, CreateRecipeResponse, EmptyResponse,
|
||||
IngredientInfo, ListRecipesResponse, RecipeInfo, RecipeIngredientEditRequest,
|
||||
RecipeRenameRequest,
|
||||
};
|
||||
use axum::{
|
||||
async_trait,
|
||||
|
|
@ -208,3 +209,20 @@ pub(super) async fn delete_ig(
|
|||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
||||
pub(super) async fn add_ig_request(
|
||||
State(state): State<AppState>,
|
||||
RecipeExtractor(recipe): RecipeExtractor,
|
||||
IngredientExtractor(ingredient): IngredientExtractor,
|
||||
Json(req): Json<AddRecipeIngredientRequest>,
|
||||
) -> JsonResult<EmptyResponse> {
|
||||
let model = recipe_ingerdients::ActiveModel {
|
||||
recipe_id: ActiveValue::Set(recipe.id),
|
||||
ingredient_id: ActiveValue::Set(ingredient.id),
|
||||
amount: ActiveValue::Set(req.amount),
|
||||
};
|
||||
|
||||
model.insert(&state.db).await?;
|
||||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue