app,server: Allow to edit recipe ingredients
This commit is contained in:
parent
47b547caf4
commit
6004520fb9
6 changed files with 307 additions and 35 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use api::{
|
||||
CreateRecipeRequest, CreateRecipeResponse, EmptyResponse, IngredientInfo, ListRecipesResponse,
|
||||
RecipeInfo, RecipeRenameRequest,
|
||||
RecipeInfo, RecipeIngredientEditRequest, RecipeRenameRequest,
|
||||
};
|
||||
use axum::{
|
||||
async_trait,
|
||||
|
|
@ -12,7 +12,10 @@ use sea_orm::{prelude::*, ActiveValue, TransactionTrait};
|
|||
|
||||
use crate::entity::{ingredient, prelude::*, recipe, recipe_ingerdients, recipe_steps};
|
||||
|
||||
use super::{household::AuthorizedHousehold, AppState, JsonResult, RouteError};
|
||||
use super::{
|
||||
household::AuthorizedHousehold, ingredients::IngredientExtractor, AppState, JsonResult,
|
||||
RouteError,
|
||||
};
|
||||
|
||||
pub(super) async fn create_recipe(
|
||||
AuthorizedHousehold(household): AuthorizedHousehold,
|
||||
|
|
@ -176,3 +179,32 @@ pub(super) async fn edit_name(
|
|||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
||||
pub(super) async fn edit_ig_amount(
|
||||
State(state): State<AppState>,
|
||||
RecipeExtractor(recipe): RecipeExtractor,
|
||||
IngredientExtractor(ingredient): IngredientExtractor,
|
||||
Json(req): Json<RecipeIngredientEditRequest>,
|
||||
) -> JsonResult<EmptyResponse> {
|
||||
let active_model = recipe_ingerdients::ActiveModel {
|
||||
recipe_id: ActiveValue::Set(recipe.id),
|
||||
ingredient_id: ActiveValue::Set(ingredient.id),
|
||||
amount: ActiveValue::Set(req.amount),
|
||||
};
|
||||
|
||||
active_model.update(&state.db).await?;
|
||||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
||||
pub(super) async fn delete_ig(
|
||||
State(state): State<AppState>,
|
||||
RecipeExtractor(recipe): RecipeExtractor,
|
||||
IngredientExtractor(ingredient): IngredientExtractor,
|
||||
) -> JsonResult<EmptyResponse> {
|
||||
RecipeIngerdients::delete_by_id((recipe.id, ingredient.id))
|
||||
.exec(&state.db)
|
||||
.await?;
|
||||
|
||||
Ok(EmptyResponse {}.into())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue