1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-19 13:19:41 +02:00

feat: add the selected recipe servings and yields in the content of the recipe post action (#5340)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
Felix Schneider 2025-06-18 21:57:51 +02:00 committed by GitHub
parent ac984a2d04
commit 78b55c0b98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import { useUserApi } from "~/composables/api";
import { GroupRecipeActionOut, GroupRecipeActionType } from "~/lib/api/types/household"; import { GroupRecipeActionOut, GroupRecipeActionType } from "~/lib/api/types/household";
import { RequestResponse } from "~/lib/api/types/non-generated"; import { RequestResponse } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe"; import { Recipe } from "~/lib/api/types/recipe";
import { useScaledAmount } from "~/composables/recipes/use-scaled-amount";
const groupRecipeActions = ref<GroupRecipeActionOut[] | null>(null); const groupRecipeActions = ref<GroupRecipeActionOut[] | null>(null);
const loading = ref(false); const loading = ref(false);
@ -69,7 +70,7 @@ export const useGroupRecipeActions = function (
window.open(url, "_blank")?.focus(); window.open(url, "_blank")?.focus();
return; return;
case "post": case "post":
return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || ""); return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || "", useScaledAmount(recipe.recipeServings || 1, recipeScale).scaledAmount);
default: default:
break; break;
} }

View file

@ -13,7 +13,7 @@ const routes = {
baseRoute = routes.groupRecipeActions; baseRoute = routes.groupRecipeActions;
itemRoute = routes.groupRecipeActionsId; itemRoute = routes.groupRecipeActionsId;
async triggerAction(id: string | number, recipeSlug: string) { async triggerAction(id: string | number, recipeSlug: string, scaledAmount: number) {
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {}); return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {scaledAmount});
} }
} }

View file

@ -1,7 +1,7 @@
from functools import cached_property from functools import cached_property
import requests import requests
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, status from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException, status
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
from pydantic import UUID4 from pydantic import UUID4
@ -68,7 +68,9 @@ class GroupRecipeActionController(BaseUserController):
# Actions # Actions
@router.post("/{item_id}/trigger/{recipe_slug}", status_code=202) @router.post("/{item_id}/trigger/{recipe_slug}", status_code=202)
def trigger_action(self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks) -> None: def trigger_action(
self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks, scaled_amount: float = Body(1, embed=True)
) -> 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(
@ -93,7 +95,7 @@ class GroupRecipeActionController(BaseUserController):
detail=ErrorResponse.respond(message="Not found."), detail=ErrorResponse.respond(message="Not found."),
) from e ) from e
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe) payload = GroupRecipeActionPayload(action=recipe_action, content=recipe, scaled_amount=scaled_amount)
bg_tasks.add_task( bg_tasks.add_task(
task_action, task_action,
url=recipe_action.url, url=recipe_action.url,

View file

@ -44,3 +44,4 @@ class GroupRecipeActionPagination(PaginationBase):
class GroupRecipeActionPayload(MealieModel): class GroupRecipeActionPayload(MealieModel):
action: GroupRecipeActionOut action: GroupRecipeActionOut
content: Any content: Any
scaled_amount: float

View file

@ -173,6 +173,7 @@ def test_group_recipe_actions_trigger_post(
response = api_client.post( response = api_client.post(
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug), api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug),
headers=unique_user.token, headers=unique_user.token,
json={"scaled_amount": 1.0},
) )
if missing_action or missing_recipe: if missing_action or missing_recipe:
@ -189,6 +190,7 @@ def test_group_recipe_actions_trigger_invalid_type(api_client: TestClient, uniqu
response = api_client.post( response = api_client.post(
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id), api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id),
headers=unique_user.token, headers=unique_user.token,
json={"scaled_amount": 1.0},
) )
assert response.status_code == 400 assert response.status_code == 400