Skip to content

Commit

Permalink
criar metodo e end-point
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruan-Carvalho committed Aug 7, 2024
1 parent a04e209 commit 2d47d5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/controller/savedVideosController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
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}
7 changes: 7 additions & 0 deletions src/repository/savedVideosRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2d47d5a

Please sign in to comment.