This commit is contained in:
Marek Lenczewski
2026-04-08 08:51:59 +02:00
parent 375a9cd386
commit a0c8ecaf27
12 changed files with 75 additions and 92 deletions

View File

@@ -1,13 +1,38 @@
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from fastapi import APIRouter
from api.schemas import ProfileResponse
from database.database import getDb
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(prefix="/profiles", tags=["profiles"])
router = APIRouter()
@router.get("", response_model=list[ProfileResponse])
def getAll(db: Session = Depends(getDb)):
@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}