diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index 074c6bf..31e9116 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -39,3 +39,8 @@ def check_watch_later(video_id: str, user_id: str = Query(...), db: Session = De @favorite.post("/") def add_to_favorite(favorite: savedVideosSchema.FavoriteCreate, db: Session = Depends(get_db)): return savedVideosRepository.create_favorite(db=db, favorite=favorite) + +@favorite.get("/status/{video_id}") +def check_favorite(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): + status = savedVideosRepository.check_favorite_status(db=db, video_id=video_id, user_id=user_id) + return status diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index a4562f4..1386606 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -64,4 +64,19 @@ def create_favorite(db: Session, favorite: savedVideosSchema.FavoriteCreate): db.commit() db.refresh(db_favorite) return db_favorite - \ No newline at end of file + +def check_favorite_status(db: Session, video_id: str, user_id: str) -> dict: + video_id = video_id.strip() + user_id = user_id.strip() + favorite_entry = db.query(savedVideosModel.WatchLater).filter( + savedVideosModel.WatchLater.user_id == user_id, + savedVideosModel.WatchLater.video_id == video_id, + savedVideosModel.WatchLater.statusfavorite == True + ).first() + if favorite_entry: + return { + "statusfavorite": favorite_entry.statusfavorite + } + return { + "statusfavorite": False + } diff --git a/tests/junit.xml b/tests/junit.xml new file mode 100644 index 0000000..a8fd4bc --- /dev/null +++ b/tests/junit.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/test.db b/tests/test.db new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_favorite.py b/tests/test_favorite.py index 90b10fd..fc7ccd0 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -46,3 +46,9 @@ def test_add_to_favorite(setup_database): assert response.json()["video_id"] == "video123" assert response.json()["statusfavorite"] is True +def test_check_favorite(setup_database): + response = client.get("/api/favorite/status/video123?user_id=user123") + print(response.json()) + assert response.status_code == 200 + assert response.json()["statusfavorite"] is True +