From c83d3d9726a0198263249df2f67d1d767440d9cc Mon Sep 17 00:00:00 2001 From: Felix Schneider Date: Tue, 29 Apr 2025 17:43:04 +0200 Subject: [PATCH] Revert "feat: add the selected recipe servings and yields in the content of the recipe post action" This reverts commit 81c8cf3ac542d9d1be457d4a79552ff0bf001af8. --- .../composables/use-group-recipe-actions.ts | 19 ++++++------------- frontend/lib/api/user/group-recipe-actions.ts | 6 +++--- .../controller_group_recipe_actions.py | 8 ++------ .../test_group_recipe_actions.py | 4 ++-- tests/utils/api_routes/__init__.py | 6 +++--- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/frontend/composables/use-group-recipe-actions.ts b/frontend/composables/use-group-recipe-actions.ts index f2cc6cbbc..d1c5171e7 100644 --- a/frontend/composables/use-group-recipe-actions.ts +++ b/frontend/composables/use-group-recipe-actions.ts @@ -46,7 +46,10 @@ export const useGroupRecipeActions = function ( return groupRecipeActions.value; }); - function parseRecipeActionUrl(url: string, recipe: Recipe, recipeServings: number, recipeYieldQuantity: number): string { + function parseRecipeActionUrl(url: string, recipe: Recipe, recipeScale: number): string { + const recipeServings = (recipe.recipeServings || 1) * recipeScale; + const recipeYieldQuantity = (recipe.recipeYieldQuantity || 1) * recipeScale; + /* eslint-disable no-template-curly-in-string */ return url .replace("${url}", window.location.href) @@ -59,29 +62,19 @@ export const useGroupRecipeActions = function ( }; async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise> { - const [recipeServings, recipeYieldQuantity] = calculateRecipeServingsAndYieldQuantity(recipe, recipeScale); - const url = parseRecipeActionUrl(action.url, recipe, recipeServings, recipeYieldQuantity); + const url = parseRecipeActionUrl(action.url, recipe, recipeScale); switch (action.actionType) { case "link": window.open(url, "_blank")?.focus(); return; case "post": - return await api.groupRecipeActions.triggerAction( - action.id, - recipe.slug || "", - recipeServings, - recipeYieldQuantity - ); + return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || ""); default: break; } }; - function calculateRecipeServingsAndYieldQuantity(recipe: Recipe, recipeScale: number): [number, number] { - return [(recipe.recipeServings || 1) * recipeScale, (recipe.recipeYieldQuantity || 1) * recipeScale]; - } - if (!groupRecipeActions.value && !loading.value) { refreshGroupRecipeActions(); }; diff --git a/frontend/lib/api/user/group-recipe-actions.ts b/frontend/lib/api/user/group-recipe-actions.ts index 94e44d41f..d49cdecec 100644 --- a/frontend/lib/api/user/group-recipe-actions.ts +++ b/frontend/lib/api/user/group-recipe-actions.ts @@ -6,14 +6,14 @@ const prefix = "/api"; const routes = { groupRecipeActions: `${prefix}/households/recipe-actions`, groupRecipeActionsId: (id: string | number) => `${prefix}/households/recipe-actions/${id}`, - groupRecipeActionsIdTriggerRecipeSlug: (id: string | number, recipeSlug: string, servings: number, yield_quantity: number) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}/${servings}/${yield_quantity}`, + groupRecipeActionsIdTriggerRecipeSlug: (id: string | number, recipeSlug: string) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}`, }; export class GroupRecipeActionsAPI extends BaseCRUDAPI { baseRoute = routes.groupRecipeActions; itemRoute = routes.groupRecipeActionsId; - async triggerAction(id: string | number, recipeSlug: string, servings: number, yield_quantity: number) { - return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug, servings, yield_quantity), {}); + async triggerAction(id: string | number, recipeSlug: string) { + return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {}); } } diff --git a/mealie/routes/households/controller_group_recipe_actions.py b/mealie/routes/households/controller_group_recipe_actions.py index d8705af70..a99c57765 100644 --- a/mealie/routes/households/controller_group_recipe_actions.py +++ b/mealie/routes/households/controller_group_recipe_actions.py @@ -67,10 +67,8 @@ class GroupRecipeActionController(BaseUserController): # ================================================================================================================== # Actions - @router.post("/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}", status_code=202) - def trigger_action( - self, item_id: UUID4, recipe_slug: str, servings: int, yield_quantity: int, bg_tasks: BackgroundTasks - ) -> None: + @router.post("/{item_id}/trigger/{recipe_slug}", status_code=202) + def trigger_action(self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks) -> None: recipe_action = self.repos.group_recipe_actions.get_one(item_id) if not recipe_action: raise HTTPException( @@ -95,8 +93,6 @@ class GroupRecipeActionController(BaseUserController): detail=ErrorResponse.respond(message="Not found."), ) from e - recipe.recipe_servings = servings - recipe.recipe_yield_quantity = yield_quantity payload = GroupRecipeActionPayload(action=recipe_action, content=recipe) bg_tasks.add_task( task_action, diff --git a/tests/integration_tests/user_household_tests/test_group_recipe_actions.py b/tests/integration_tests/user_household_tests/test_group_recipe_actions.py index ec71dfb81..b55a9bfc6 100644 --- a/tests/integration_tests/user_household_tests/test_group_recipe_actions.py +++ b/tests/integration_tests/user_household_tests/test_group_recipe_actions.py @@ -171,7 +171,7 @@ def test_group_recipe_actions_trigger_post( recipe_slug = recipe.slug response = api_client.post( - api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug, 1, 1), + api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug), headers=unique_user.token, ) @@ -187,7 +187,7 @@ def test_group_recipe_actions_trigger_invalid_type(api_client: TestClient, uniqu recipe = unique_user.repos.recipes.create(new_recipe(unique_user)) response = api_client.post( - api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id, 1, 1), + api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id), headers=unique_user.token, ) diff --git a/tests/utils/api_routes/__init__.py b/tests/utils/api_routes/__init__.py index 1a923a41f..02aee25c9 100644 --- a/tests/utils/api_routes/__init__.py +++ b/tests/utils/api_routes/__init__.py @@ -365,9 +365,9 @@ def households_recipe_actions_item_id(item_id): return f"{prefix}/households/recipe-actions/{item_id}" -def households_recipe_actions_item_id_trigger_recipe_slug(item_id, recipe_slug, servings, yield_quantity): - """`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}`""" - return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}" +def households_recipe_actions_item_id_trigger_recipe_slug(item_id, recipe_slug): + """`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}`""" + return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}" def households_self_recipes_recipe_slug(recipe_slug):