TICKET-004: Day summary endpoint

- GET /api/log/summary?date= with totals vs historical target
- Nutrition math consolidated in services/nutrition.py (weight vs count)
- Null nutrition contributes 0; meals contribute 0 (TODO TICKET-007)
- Full suite green (104 passed)
This commit is contained in:
Craig
2026-07-26 13:27:03 +01:00
parent 87d7eca468
commit 5372e8cbca
5 changed files with 482 additions and 2 deletions
+35
View File
@@ -182,3 +182,38 @@ class TargetRead(BaseModel):
protein_g: float | None
carbs_g: float | None
fat_g: float | None
# ── Day Summary (TICKET-004) ────────────────────────────────────────────────
class DaySummaryNutrition(BaseModel):
"""Summed nutrition totals for a single day.
All fields are floats (summed from scaled per-unit values).
Foods with null nutrition fields contribute 0.
"""
calories: float
protein_g: float
carbs_g: float
fat_g: float
fiber_g: float
saturated_fat_g: float
sugars_g: float
sodium_g: float
class DaySummaryResponse(BaseModel):
"""Response shape for GET /api/log/summary — the contract the frontend
ProgressBar consumes.
Remaining-vs-target arithmetic: LEFT TO THE FRONTEND.
The server returns raw totals and the applicable target (or null).
The frontend computes remaining = target.calories - totals.calories
and similar for macros where both target and total exist.
"""
date: date
totals: DaySummaryNutrition
target: TargetRead | None