Skip to content

Commit

Permalink
Adicao dos metodos check/get do favorite e teste
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeJRdev committed Aug 3, 2024
1 parent 4a2011e commit 0b3b42b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/controller/savedVideosController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion src/repository/savedVideosRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ def create_favorite(db: Session, favorite: savedVideosSchema.FavoriteCreate):
db.commit()
db.refresh(db_favorite)
return db_favorite


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
}
1 change: 1 addition & 0 deletions tests/junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="9" time="2.868" timestamp="2024-08-03T15:16:40.666896" hostname="dc999a51f205"><testcase classname="test_favorite" name="test_add_to_favorite" time="0.045" /><testcase classname="test_favorite" name="test_check_favorite" time="0.007" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day" time="1.197" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day_invalid" time="0.003" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day" time="0.582" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day_exception_handling" time="0.004" /><testcase classname="test_watch_later" name="test_add_to_watch_later" time="0.008" /><testcase classname="test_watch_later" name="test_check_watch_later_status" time="0.007" /><testcase classname="test_watch_later" name="test_remove_from_watch_later" time="0.013" /></testsuite></testsuites>
Empty file added tests/test.db
Empty file.
6 changes: 6 additions & 0 deletions tests/test_favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0b3b42b

Please sign in to comment.