Skip to content

Commit

Permalink
Realizacao do merge da branch 9_lista_favoritos
Browse files Browse the repository at this point in the history
US09 - Eu, como usuário, quero ver minha lista de vídeos favoritos em um único lugar, para organizar meu conteúdo preferido.
  • Loading branch information
GabrielRoger07 authored Aug 10, 2024
2 parents a04e209 + 41a0428 commit 27d7b41
Show file tree
Hide file tree
Showing 3 changed files with 36 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
23 changes: 23 additions & 0 deletions tests/test_favorite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest, sys, os
import uuid


sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
Expand Down Expand Up @@ -64,3 +65,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


0 comments on commit 27d7b41

Please sign in to comment.