mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 07:39: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:
parent
ac984a2d04
commit
78b55c0b98
5 changed files with 12 additions and 6 deletions
|
@ -4,6 +4,7 @@ import { useUserApi } from "~/composables/api";
|
|||
import { GroupRecipeActionOut, GroupRecipeActionType } from "~/lib/api/types/household";
|
||||
import { RequestResponse } from "~/lib/api/types/non-generated";
|
||||
import { Recipe } from "~/lib/api/types/recipe";
|
||||
import { useScaledAmount } from "~/composables/recipes/use-scaled-amount";
|
||||
|
||||
const groupRecipeActions = ref<GroupRecipeActionOut[] | null>(null);
|
||||
const loading = ref(false);
|
||||
|
@ -69,7 +70,7 @@ export const useGroupRecipeActions = function (
|
|||
window.open(url, "_blank")?.focus();
|
||||
return;
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ const routes = {
|
|||
baseRoute = routes.groupRecipeActions;
|
||||
itemRoute = routes.groupRecipeActionsId;
|
||||
|
||||
async triggerAction(id: string | number, recipeSlug: string) {
|
||||
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {});
|
||||
async triggerAction(id: string | number, recipeSlug: string, scaledAmount: number) {
|
||||
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {scaledAmount});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from functools import cached_property
|
||||
|
||||
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 pydantic import UUID4
|
||||
|
||||
|
@ -68,7 +68,9 @@ class GroupRecipeActionController(BaseUserController):
|
|||
# Actions
|
||||
|
||||
@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)
|
||||
if not recipe_action:
|
||||
raise HTTPException(
|
||||
|
@ -93,7 +95,7 @@ class GroupRecipeActionController(BaseUserController):
|
|||
detail=ErrorResponse.respond(message="Not found."),
|
||||
) from e
|
||||
|
||||
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe)
|
||||
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe, scaled_amount=scaled_amount)
|
||||
bg_tasks.add_task(
|
||||
task_action,
|
||||
url=recipe_action.url,
|
||||
|
|
|
@ -44,3 +44,4 @@ class GroupRecipeActionPagination(PaginationBase):
|
|||
class GroupRecipeActionPayload(MealieModel):
|
||||
action: GroupRecipeActionOut
|
||||
content: Any
|
||||
scaled_amount: float
|
||||
|
|
|
@ -173,6 +173,7 @@ def test_group_recipe_actions_trigger_post(
|
|||
response = api_client.post(
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug),
|
||||
headers=unique_user.token,
|
||||
json={"scaled_amount": 1.0},
|
||||
)
|
||||
|
||||
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(
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id),
|
||||
headers=unique_user.token,
|
||||
json={"scaled_amount": 1.0},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue