Spaces:
Running
Running
Download app/api/v1/endpoints/library.py from MonteeqOrg/backend: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/MonteeqOrg/backend/resolve/main/app/api/v1/endpoints/library.py
- Command line
-
hf download hf://spaces/MonteeqOrg/backend/app/api/v1/endpoints/library.py
-
curl -L -o library.py https://huggingface.co/spaces/MonteeqOrg/backend/resolve/main/app/api/v1/endpoints/library.py
1.08 kB
| from fastapi import APIRouter, Depends | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from sqlalchemy.future import select | |
| from sqlalchemy import func | |
| from app.db.async_session import get_async_db | |
| from app.schemas import library as schemas | |
| from app.models.library import WatchHistory, LibraryWatchLater, LikedVideo | |
| from app.core.async_dependencies import get_async_current_user | |
| router = APIRouter() | |
| async def get_library_stats( | |
| db: AsyncSession = Depends(get_async_db), | |
| current_user = Depends(get_async_current_user) | |
| ): | |
| history_count = await db.scalar(select(func.count()).filter(WatchHistory.user_id == current_user.id)) | |
| watch_later_count = await db.scalar(select(func.count()).filter(LibraryWatchLater.user_id == current_user.id)) | |
| liked_count = await db.scalar(select(func.count()).filter(LikedVideo.user_id == current_user.id)) | |
| return { | |
| "history_count": history_count or 0, | |
| "watch_later_count": watch_later_count or 0, | |
| "liked_count": liked_count or 0 | |
| } | |