From 17e31137c6e10bcf6cd92418e2fc2ade64e3d390 Mon Sep 17 00:00:00 2001 From: gabrielhrlima Date: Thu, 1 Aug 2024 20:36:22 -0300 Subject: [PATCH] Cria os metodos utilizados nos endpoints --- src/model/watchLaterModel.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/model/watchLaterModel.py b/src/model/watchLaterModel.py index 04bc340..8002b4b 100644 --- a/src/model/watchLaterModel.py +++ b/src/model/watchLaterModel.py @@ -12,4 +12,32 @@ class WatchLater(Base): video_id = Column(String, index= True, nullable = False) status = Column(Boolean, default = True) - \ No newline at end of file +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 \ No newline at end of file