From 2708cc4bdd1d2932388d60a52fd0fec8fdd5e115 Mon Sep 17 00:00:00 2001 From: Peter Woolery Date: Fri, 15 May 2026 14:11:36 -0700 Subject: [PATCH] fix: enrich ingredient names in meal detail API Recipe JSONB stores ingredient_id but not name. GET /api/meals/items/{id} now queries the Ingredient table and injects names into the response so the frontend displays "3 cups onion" instead of just "3 cups". --- backend/app/api/meals.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/app/api/meals.py b/backend/app/api/meals.py index 4829385..2b38c7a 100644 --- a/backend/app/api/meals.py +++ b/backend/app/api/meals.py @@ -6,7 +6,7 @@ from sqlalchemy import text from sqlalchemy.orm import Session, joinedload from app.database import get_db from app.models import ( - MealPlan, MealPlanItem, MealPlanVote, Recipe, + MealPlan, MealPlanItem, MealPlanVote, Recipe, Ingredient, FamilyProfile, FamilyMember, ApprovalToken, MealPlanStatus, MealPlanItemStatus, MealType, ApprovalTokenStatus ) @@ -304,6 +304,18 @@ def get_meal_item(item_id: UUID, db: Session = Depends(get_db)): ).first() if not item: raise HTTPException(status_code=404, detail="Meal plan item not found") + + # Enrich ingredient names from the Ingredient table + if item.recipe and item.recipe.ingredients: + ing_ids = [ing.get("ingredient_id") for ing in item.recipe.ingredients if ing.get("ingredient_id")] + if ing_ids: + ingredients = db.query(Ingredient).filter(Ingredient.id.in_(ing_ids)).all() + name_map = {str(i.id): i.name for i in ingredients} + for ing in item.recipe.ingredients: + ing_id = str(ing.get("ingredient_id", "")) + if ing_id in name_map and not ing.get("name"): + ing["name"] = name_map[ing_id] + return item