update
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user