"""Progress tracking endpoints. GET /progress — full syllabus progress with completion % PATCH /progress/{topic_id} — update a topic's status """ from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.ext.asyncio import AsyncSession from app.core.dependencies import get_current_user from app.database import get_db from app.models.user import User from app.schemas.progress import ProgressResponse, ProgressUpdateRequest from app.services.progress_service import get_full_progress, update_topic_progress router = APIRouter(prefix="/progress", tags=["progress"]) VALID_STATUSES = {"not_started", "in_progress", "completed"} @router.get("", response_model=ProgressResponse) async def get_progress( user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db), ): """Return the authenticated user's full syllabus progress.""" return await get_full_progress(user.id, db) @router.patch("/{topic_id}") async def update_progress( topic_id: str, body: ProgressUpdateRequest, user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db), ): """Update a topic's study status.""" if body.status not in VALID_STATUSES: raise HTTPException(400, f"Invalid status. Must be one of: {VALID_STATUSES}") progress = await update_topic_progress(user.id, topic_id, body.status, db) return {"topic_id": progress.topic_id, "status": progress.status}