feat(backend): persist plan scores on MealPlanItem

- Migration 0012 adds score (float) and components (jsonb) to meal_plan_item
- generate.py: populates score and components at create time
- schemas/MealPlanItemResponse: include score + components fields
- GET /api/meal-plans/{id}: returns persisted values instead of zeros
This commit is contained in:
2026-05-24 20:20:11 -07:00
parent c96b41ec26
commit e22eae1ecd
5 changed files with 32 additions and 5 deletions
+3 -4
View File
@@ -125,8 +125,7 @@ def get_plan(plan_id: UUID, db: Session = Depends(get_db)) -> GenerationResponse
.order_by(MealPlanItem.day_of_week)
.all()
)
# Read-after-create: scores not stored on MealPlanItem, so we return zeros
# for score/components. The original generate response is authoritative.
# Read-after-create: scores now stored on MealPlanItem
return GenerationResponse(
meal_plan_id=plan.id,
week_start_date=plan.week_start_date,
@@ -135,8 +134,8 @@ def get_plan(plan_id: UUID, db: Session = Depends(get_db)) -> GenerationResponse
recipe_id=it.recipe_id,
day_of_week=it.day_of_week,
estimated_cost=it.estimated_cost or 0,
score=0.0,
components={},
score=it.score or 0.0,
components={k: float(v) for k, v in (it.components.items() if it.components else [])},
)
for it in items
],