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
+7 -1
View File
@@ -6,7 +6,7 @@ from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from database import get_db
from schemas import LogEntryCreate, LogEntryRead, LogEntryUpdate
from schemas import DaySummaryResponse, LogEntryCreate, LogEntryRead, LogEntryUpdate
from services import log as svc
router = APIRouter(prefix="/api/log", tags=["log"])
@@ -29,6 +29,12 @@ def create_log_entry(data: LogEntryCreate, db: Session = Depends(get_db)):
raise HTTPException(status_code=404, detail=str(e))
@router.get("/summary", response_model=DaySummaryResponse)
def get_day_summary(date: date, db: Session = Depends(get_db)):
"""Computed nutrition totals for the day vs. the applicable target (§3.3)."""
return svc.get_day_summary(db, date)
@router.put("/{entry_id}", response_model=LogEntryRead)
def update_log_entry(entry_id: int, data: LogEntryUpdate, db: Session = Depends(get_db)):
"""Update quantity, meal_slot, and/or sort_order.