from fastapi import APIRouter from api.schemas import CleanupRequest, VideoCreate, VideoResponse from database.database import DbSession from model.profile import Profile from model.video import Video from notify.notify_clients import notifyClients router = APIRouter() @router.get("/profiles") def getAll(db: DbSession): return Profile.getAll(db) @router.post("/profiles/{profileId}/videos", status_code=204) async def createVideo(profileId: int, videoData: VideoCreate, db: DbSession): title = videoData.title youtuber = videoData.youtuber thumbnailUrl = videoData.thumbnailUrl youtubeUrl = videoData.youtubeUrl Video.deleteIfExists(db, youtubeUrl, profileId) Video.create(db, title, youtuber, thumbnailUrl, youtubeUrl, profileId) await notifyClients(profileId) @router.get("/profiles/{profileId}/videos", response_model=list[VideoResponse]) def getVideos(profileId: int, db: DbSession): return Video.getAll(db, profileId=profileId) @router.post("/profiles/{profileId}/videos/cleanup") def cleanupVideos(profileId: int, request: CleanupRequest, db: DbSession): excludeIds = request.excludeIds count = Video.deleteNotDownloaded(db, profileId, excludeIds) return {"deleted": count}