Spaces:
Sleeping
Sleeping
Download src/api/stats.py from hashir-qt/tasklert-api: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/src/api/stats.py
- Command line
-
hf download hf://spaces/hashir-qt/tasklert-api/src/api/stats.py
-
curl -L -o stats.py https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/src/api/stats.py
1.33 kB
| """Phase V: Stats, heatmap, and achievements API routes.""" | |
| import logging | |
| from typing import Annotated | |
| from fastapi import APIRouter, Depends, Header | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from ..core.database import get_session | |
| from ..core.better_auth import get_current_user_from_session | |
| from ..services import stats_service | |
| logger = logging.getLogger(__name__) | |
| router = APIRouter(prefix="/stats", tags=["Stats"]) | |
| async def get_stats( | |
| authorization: Annotated[str | None, Header()] = None, | |
| cookie: Annotated[str | None, Header()] = None, | |
| session: AsyncSession = Depends(get_session), | |
| ): | |
| """Return heatmap data, streaks, and achievements for the authenticated user.""" | |
| current_user = await get_current_user_from_session(authorization, cookie, session) | |
| return await stats_service.get_stats(session, current_user.id) | |
| async def get_achievements( | |
| authorization: Annotated[str | None, Header()] = None, | |
| cookie: Annotated[str | None, Header()] = None, | |
| session: AsyncSession = Depends(get_session), | |
| ): | |
| """Return all unlocked achievements for the authenticated user.""" | |
| current_user = await get_current_user_from_session(authorization, cookie, session) | |
| return await stats_service.get_achievements(session, current_user.id) | |