feat(meal-planner): add is_from_recipe_box field to get_meal_plan (v0.10.3)
Join recipeList[] from API response as a lookup table: isRecipe="true" means a real recipe from the recipe box, "false" is a free-text stub. Dish entries get is_from_recipe_box=true/false; meal entries get null. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2231,15 +2231,18 @@ def get_meal_plan(date_from: str, date_to: str) -> str:
|
||||
JSON list of meal plan entries sorted by date then meal type
|
||||
(BREAKFAST → LUNCH → SNACK → DINNER), with keys:
|
||||
|
||||
- ``id`` — metaId (``dish/…`` or ``meal/…``)
|
||||
- ``date`` — ISO date string
|
||||
- ``type`` — ``BREAKFAST``, ``LUNCH``, ``SNACK``, or ``DINNER``
|
||||
- ``name`` — dish name, or ``null`` for meal entries
|
||||
- ``recipe_id`` — linked recipe metaId, or ``null``
|
||||
- ``note`` — free-text note (meal entries only), or ``null``
|
||||
- ``serves`` — number of servings as int (meal entries only), or ``null``
|
||||
- ``can_update`` — whether the entry can be updated
|
||||
- ``can_delete`` — whether the entry can be deleted
|
||||
- ``id`` — metaId (``dish/…`` or ``meal/…``)
|
||||
- ``date`` — ISO date string
|
||||
- ``type`` — ``BREAKFAST``, ``LUNCH``, ``SNACK``, or ``DINNER``
|
||||
- ``name`` — dish name, or ``null`` for meal entries
|
||||
- ``recipe_id`` — linked recipe metaId, or ``null``
|
||||
- ``is_from_recipe_box`` — ``true`` if the linked recipe was pulled from the
|
||||
recipe box; ``false`` if it is a free-text stub (name only, no ingredients);
|
||||
``null`` for meal entries or when no recipe is linked
|
||||
- ``note`` — free-text note (meal entries only), or ``null``
|
||||
- ``serves`` — number of servings as int (meal entries only), or ``null``
|
||||
- ``can_update`` — whether the entry can be updated
|
||||
- ``can_delete`` — whether the entry can be deleted
|
||||
|
||||
Returns an error message string on failure.
|
||||
"""
|
||||
@@ -2261,6 +2264,16 @@ def get_meal_plan(date_from: str, date_to: str) -> str:
|
||||
|
||||
raw_dishes: list[dict[str, Any]] = payload.get("list") or []
|
||||
raw_meals: list[dict[str, Any]] = payload.get("mealList") or []
|
||||
raw_recipe_list: list[dict[str, Any]] = payload.get("recipeList") or []
|
||||
|
||||
# Build lookup: recipeId → is_from_recipe_box
|
||||
# recipeList[] contains one entry per linked recipe; isRecipe="true" means it is
|
||||
# a real recipe from the recipe box, "false" means a free-text stub (name only).
|
||||
recipe_lookup: dict[str, bool] = {
|
||||
r["metaId"]: r.get("isRecipe") == "true"
|
||||
for r in raw_recipe_list
|
||||
if isinstance(r, dict) and "metaId" in r
|
||||
}
|
||||
|
||||
_type_order = {"BREAKFAST": 0, "LUNCH": 1, "SNACK": 2, "DINNER": 3}
|
||||
|
||||
@@ -2268,13 +2281,15 @@ def get_meal_plan(date_from: str, date_to: str) -> str:
|
||||
|
||||
for dish in raw_dishes:
|
||||
rights = dish.get("rights") or {}
|
||||
recipe_id: str | None = dish.get("recipeId") or None
|
||||
result.append(
|
||||
{
|
||||
"id": dish.get("metaId"),
|
||||
"date": dish.get("date"),
|
||||
"type": dish.get("type"),
|
||||
"name": dish.get("name"),
|
||||
"recipe_id": dish.get("recipeId") or None,
|
||||
"recipe_id": recipe_id,
|
||||
"is_from_recipe_box": recipe_lookup.get(recipe_id) if recipe_id else None,
|
||||
"note": None,
|
||||
"serves": None,
|
||||
"can_update": rights.get("canUpdate") == "true",
|
||||
@@ -2292,6 +2307,7 @@ def get_meal_plan(date_from: str, date_to: str) -> str:
|
||||
"type": meal.get("type"),
|
||||
"name": None,
|
||||
"recipe_id": None,
|
||||
"is_from_recipe_box": None,
|
||||
"note": meal.get("note") or None,
|
||||
"serves": int(raw_serves) if raw_serves is not None else None,
|
||||
"can_update": rights.get("canUpdate") == "true",
|
||||
|
||||
Reference in New Issue
Block a user