fitness-web/app/routers/dashboard.py
Jacob Hinkle 1a2509ab34 Add Plan page with phase timeline and agent phase management API
- New /plan page shows all phases in order with current phase highlighted
- Add GET/POST/PUT /api/agent/phases endpoints for the AI coach
- Plan link added to navigation bar
- Agent config updated with phase management instructions
2026-06-29 10:51:28 -04:00

52 lines
1.7 KiB
Python

from fastapi import APIRouter, Request, Depends
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from sqlalchemy import select, desc
from app.models.base import async_session
from app.models.user import User
from app.models.workout import Phase, Workout
from app.models.checkin import Checkin
from app.auth import get_current_user
router = APIRouter()
templates = Jinja2Templates(directory="app/templates")
@router.get("/", response_class=HTMLResponse)
async def root_redirect():
from fastapi.responses import RedirectResponse
return RedirectResponse(url="/dashboard")
@router.get("/dashboard", response_class=HTMLResponse)
async def dashboard(request: Request, user: User = Depends(get_current_user)):
async with async_session() as session:
result = await session.execute(
select(Workout)
.where(Workout.user_id == user.id)
.order_by(desc(Workout.date))
.limit(5)
)
recent_workouts = result.scalars().all()
result = await session.execute(
select(Checkin)
.where(Checkin.user_id == user.id)
.order_by(desc(Checkin.date))
.limit(1)
)
latest_checkin = result.scalar_one_or_none()
result = await session.execute(
select(Phase).order_by(Phase.start_date.desc().nulls_last()).limit(1)
)
current_phase = result.scalar_one_or_none()
return templates.TemplateResponse(request, "dashboard.html", {
"user": user,
"recent_workouts": recent_workouts,
"latest_checkin": latest_checkin,
"current_phase": current_phase,
})