From 2d47d5a4e4178fc7b9c71d4d84b81ccf58159578 Mon Sep 17 00:00:00 2001 From: Ruan-Carvalho Date: Wed, 7 Aug 2024 20:44:07 -0300 Subject: [PATCH] criar metodo e end-point --- src/controller/savedVideosController.py | 7 ++++++- src/repository/savedVideosRepository.py | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index 7be5d04..90be2b1 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -47,4 +47,9 @@ def remove_from_favorites(video_id: str, user_id: str = Query(...), db: Session user_id = user_id.strip() video_id = video_id.strip() savedVideosRepository.remove_favorite(db=db, video_id=video_id, user_id=user_id) - return {"message": "Removed from favorites"} \ No newline at end of file + return {"message": "Removed from favorites"} + +@favorite.get("/") +def get_favorite_videos(user_id: str = Query(...), db: Session = Depends(get_db)): + videos = savedVideosRepository.get_favorite_videos(db=db, user_id=user_id) + return {"videoList": videos} \ No newline at end of file diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index 1e63518..6945b50 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -99,3 +99,10 @@ def remove_favorite(db: Session, video_id: str, user_id: str): else: raise HTTPException(status_code=404, detail="Video not found in favorites") +def get_favorite_videos(db: Session, user_id: str): + user_id = user_id.strip() + favorite_entries = db.query(savedVideosModel.WatchLater).filter( + savedVideosModel.WatchLater.user_id == user_id, + savedVideosModel.WatchLater.statusfavorite == True + ).all() + return favorite_entries \ No newline at end of file