Revert "feat: add the selected recipe servings and yields in the content of the recipe post action"

This reverts commit 81c8cf3ac542d9d1be457d4a79552ff0bf001af8.
This commit is contained in:
Felix Schneider 2025-04-29 17:43:04 +02:00
commit c83d3d9726
5 changed files with 16 additions and 27 deletions

View file

@ -46,7 +46,10 @@ export const useGroupRecipeActions = function (
return groupRecipeActions.value; 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 */ /* eslint-disable no-template-curly-in-string */
return url return url
.replace("${url}", window.location.href) .replace("${url}", window.location.href)
@ -59,29 +62,19 @@ export const useGroupRecipeActions = function (
}; };
async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise<void | RequestResponse<unknown>> { async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise<void | RequestResponse<unknown>> {
const [recipeServings, recipeYieldQuantity] = calculateRecipeServingsAndYieldQuantity(recipe, recipeScale); const url = parseRecipeActionUrl(action.url, recipe, recipeScale);
const url = parseRecipeActionUrl(action.url, recipe, recipeServings, recipeYieldQuantity);
switch (action.actionType) { switch (action.actionType) {
case "link": case "link":
window.open(url, "_blank")?.focus(); window.open(url, "_blank")?.focus();
return; return;
case "post": case "post":
return await api.groupRecipeActions.triggerAction( return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || "");
action.id,
recipe.slug || "",
recipeServings,
recipeYieldQuantity
);
default: default:
break; break;
} }
}; };
function calculateRecipeServingsAndYieldQuantity(recipe: Recipe, recipeScale: number): [number, number] {
return [(recipe.recipeServings || 1) * recipeScale, (recipe.recipeYieldQuantity || 1) * recipeScale];
}
if (!groupRecipeActions.value && !loading.value) { if (!groupRecipeActions.value && !loading.value) {
refreshGroupRecipeActions(); refreshGroupRecipeActions();
}; };

View file

@ -6,14 +6,14 @@ const prefix = "/api";
const routes = { const routes = {
groupRecipeActions: `${prefix}/households/recipe-actions`, groupRecipeActions: `${prefix}/households/recipe-actions`,
groupRecipeActionsId: (id: string | number) => `${prefix}/households/recipe-actions/${id}`, 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<CreateGroupRecipeAction, GroupRecipeActionOut> { export class GroupRecipeActionsAPI extends BaseCRUDAPI<CreateGroupRecipeAction, GroupRecipeActionOut> {
baseRoute = routes.groupRecipeActions; baseRoute = routes.groupRecipeActions;
itemRoute = routes.groupRecipeActionsId; itemRoute = routes.groupRecipeActionsId;
async triggerAction(id: string | number, recipeSlug: string, servings: number, yield_quantity: number) { async triggerAction(id: string | number, recipeSlug: string) {
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug, servings, yield_quantity), {}); return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {});
} }
} }

View file

@ -67,10 +67,8 @@ class GroupRecipeActionController(BaseUserController):
# ================================================================================================================== # ==================================================================================================================
# Actions # Actions
@router.post("/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}", status_code=202) @router.post("/{item_id}/trigger/{recipe_slug}", status_code=202)
def trigger_action( def trigger_action(self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks) -> None:
self, item_id: UUID4, recipe_slug: str, servings: int, yield_quantity: int, bg_tasks: BackgroundTasks
) -> None:
recipe_action = self.repos.group_recipe_actions.get_one(item_id) recipe_action = self.repos.group_recipe_actions.get_one(item_id)
if not recipe_action: if not recipe_action:
raise HTTPException( raise HTTPException(
@ -95,8 +93,6 @@ class GroupRecipeActionController(BaseUserController):
detail=ErrorResponse.respond(message="Not found."), detail=ErrorResponse.respond(message="Not found."),
) from e ) from e
recipe.recipe_servings = servings
recipe.recipe_yield_quantity = yield_quantity
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe) payload = GroupRecipeActionPayload(action=recipe_action, content=recipe)
bg_tasks.add_task( bg_tasks.add_task(
task_action, task_action,

View file

@ -171,7 +171,7 @@ def test_group_recipe_actions_trigger_post(
recipe_slug = recipe.slug recipe_slug = recipe.slug
response = api_client.post( 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, 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)) recipe = unique_user.repos.recipes.create(new_recipe(unique_user))
response = api_client.post( 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, headers=unique_user.token,
) )

View file

@ -365,9 +365,9 @@ def households_recipe_actions_item_id(item_id):
return f"{prefix}/households/recipe-actions/{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): def households_recipe_actions_item_id_trigger_recipe_slug(item_id, recipe_slug):
"""`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}`""" """`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}`"""
return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}" return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}"
def households_self_recipes_recipe_slug(recipe_slug): def households_self_recipes_recipe_slug(recipe_slug):