mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
refactor: set scaled_amount in request body
This commit is contained in:
parent
628d8533b8
commit
b94eb30ebc
5 changed files with 17 additions and 15 deletions
|
@ -6,7 +6,7 @@ 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, scaledAmount: number) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}/${scaledAmount}`,
|
||||
groupRecipeActionsIdTriggerRecipeSlug: (id: string | number, recipeSlug: string) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}`,
|
||||
};
|
||||
|
||||
export class GroupRecipeActionsAPI extends BaseCRUDAPI<CreateGroupRecipeAction, GroupRecipeActionOut> {
|
||||
|
@ -14,6 +14,6 @@ const routes = {
|
|||
itemRoute = routes.groupRecipeActionsId;
|
||||
|
||||
async triggerAction(id: string | number, recipeSlug: string, scaledAmount: number) {
|
||||
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug, scaledAmount), {});
|
||||
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
|
||||
|
||||
|
@ -67,8 +67,10 @@ class GroupRecipeActionController(BaseUserController):
|
|||
# ==================================================================================================================
|
||||
# Actions
|
||||
|
||||
@router.post("/{item_id}/trigger/{recipe_slug}/{scaled_amount}", status_code=202)
|
||||
def trigger_action(self, item_id: UUID4, recipe_slug: str, scaled_amount: float, 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, scaled_amount: float = Body(..., embed=True)
|
||||
) -> None:
|
||||
recipe_action = self.repos.group_recipe_actions.get_one(item_id)
|
||||
if not recipe_action:
|
||||
raise HTTPException(
|
||||
|
@ -93,12 +95,10 @@ class GroupRecipeActionController(BaseUserController):
|
|||
detail=ErrorResponse.respond(message="Not found."),
|
||||
) from e
|
||||
|
||||
payload = GroupRecipeActionPayload(
|
||||
action=recipe_action, content=recipe, scaled_amount=scaled_amount
|
||||
).model_dump()
|
||||
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe, scaled_amount=scaled_amount)
|
||||
bg_tasks.add_task(
|
||||
task_action,
|
||||
url=recipe_action.url,
|
||||
json=jsonable_encoder(payload),
|
||||
json=jsonable_encoder(payload.model_dump()),
|
||||
timeout=15,
|
||||
)
|
||||
|
|
|
@ -44,4 +44,4 @@ class GroupRecipeActionPagination(PaginationBase):
|
|||
class GroupRecipeActionPayload(MealieModel):
|
||||
action: GroupRecipeActionOut
|
||||
content: Any
|
||||
scaled_amount: float | None = None
|
||||
scaled_amount: float
|
||||
|
|
|
@ -171,8 +171,9 @@ 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.0),
|
||||
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:
|
||||
|
@ -187,8 +188,9 @@ 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.0),
|
||||
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
|
||||
|
|
|
@ -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, scaled_amount):
|
||||
"""`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{scaled_amount}`"""
|
||||
return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{scaled_amount}"
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue