Spaces:
Running
Running
File size: 1,077 Bytes
3533fb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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()
@router.get("/stats", response_model=schemas.LibraryStats)
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
}
|