From 2d47d5a4e4178fc7b9c71d4d84b81ccf58159578 Mon Sep 17 00:00:00 2001 From: Ruan-Carvalho Date: Wed, 7 Aug 2024 20:44:07 -0300 Subject: [PATCH 1/3] 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 From 4476cbf5127750451ab31cf114144afcc288032d Mon Sep 17 00:00:00 2001 From: Benjamim Lacerda Date: Thu, 8 Aug 2024 11:29:19 -0300 Subject: [PATCH 2/3] Adiciona testes para getfavorite --- tests/test_favorite.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_favorite.py b/tests/test_favorite.py index 548af40..c4796c8 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -64,3 +64,25 @@ def test_remove_from_favorites(setup_database): print("Response from GET status:", response.json()) assert response.status_code == 200 assert response.json()["statusfavorite"] is False + + +def test_get_favorite_videos(): + user_id = str(uuid.uuid4()) + + # Add multiple videos to the favorite list + video_ids = [str(uuid.uuid4()) for _ in range(3)] + for video_id in video_ids: + client.post("/api/favorite/", json={"user_id": user_id, "video_id": video_id}) + + # Retrieve the favorite list + response = client.get(f"/api/favorite/?user_id={user_id}") + assert response.status_code == 200 + assert "videoList" in response.json() + video_list = response.json()["videoList"] + + # Check if the specific video is in the favorite list + retrieved_video_ids = [item["video_id"] for item in video_list] + for video_id in video_ids: + assert video_id in retrieved_video_ids + + From 41a04282fc72822497e086352c280f313d19dccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20de=20Camargo=20Vaz?= Date: Sat, 10 Aug 2024 00:30:22 -0300 Subject: [PATCH 3/3] adiciona import uuid --- tests/test_favorite.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_favorite.py b/tests/test_favorite.py index c4796c8..9c2e1a9 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -1,4 +1,5 @@ import pytest, sys, os +import uuid sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))