Skip to content

Commit

Permalink
Cria os metodos utilizados nos endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielhrlima committed Aug 1, 2024
1 parent c9f94ac commit 17e3113
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/model/watchLaterModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,32 @@ class WatchLater(Base):
video_id = Column(String, index= True, nullable = False)
status = Column(Boolean, default = True)


def create_watch_later(db: Session, watch_later: WatchLaterCreate):
db_watchl_later = WatchLater(video_id = watch_later.video_id.strip() , user_id =watch_later.user_id.strip(), status =True)
db.add(db_watch_later)
db.commit()
db.refresh(db_watch_later)
return db_watch_later

def remove_watch_later(db: Session, video_id : str, user_id : str):
video_id = video_id.strip()
user_id = user_id.strip()
watch_later_entry = db.query(WatchLater).filter(WatchLater.video_id == video_id, WatchLater.user_id == user_id, WatchLater.status == True).first()

if watch_later_entry:
db.delete(watch_later_entry)
db.commit()
return {"messege": "Removed from watch later list"}
else:
raise HTTPException(status_code= 404, detail= "Video not found in watch later list")

def check_watch_later_status(db: Session, video_id: str, user_id: str)->bool:
video_id= video_id.strip()
user_id = user_id.strip()

watch_later_entry = db.query(WatchLater).filter( WatchLater.video_id == video_id, WatchLater.user_id ==user_id, WatchLater.status ==True)

if watch_later_entry :
return watch_later_entry.status

return False

0 comments on commit 17e3113

Please sign in to comment.