Spaces:
Sleeping
Sleeping
Download app/api/v1/progress.py from baljot07/studiq-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/app/api/v1/progress.py
- Command line
-
hf download hf://spaces/baljot07/studiq-backend/app/api/v1/progress.py
-
curl -L -o progress.py https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/app/api/v1/progress.py
1.45 kB
| """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"} | |
| 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) | |
| 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} | |