From 8329e4c99c726615797391a249ffec042ad18cf0 Mon Sep 17 00:00:00 2001 From: Benjamim Lacerda Date: Thu, 1 Aug 2024 14:29:28 -0300 Subject: [PATCH 01/13] Criacao da schema --- .github/templates/bug_report.md | 0 .github/templates/feature_request.md | 0 .github/templates/pull_request_template.md | 0 .github/templates/user_stories.md | 0 .github/workflows/code-analysis.yml | 0 .github/workflows/deploy.yml | 0 .github/workflows/release.yml | 0 .gitignore | 0 Dockerfile | 0 LICENSE | 0 Procfile | 0 README.md | 0 docker-compose.yml | 0 env.example | 0 requirements.txt | 0 runtime.txt | 0 sonar-project.properties | 0 sonar_scripts/parser.py | 0 src/__init__.py | 0 src/constants/__init__.py | 0 src/constants/errorMessages.py | 0 src/controller/__init__.py | 0 src/controller/commentController.py | 0 src/controller/scheduleController.py | 0 src/database.py | 0 src/domain/__init__.py | 0 src/domain/commentSchema.py | 0 src/domain/watchLaterSchema.py | 11 +++++++++++ src/main.py | 0 src/model/__init__.py | 0 src/model/commentModel.py | 0 src/repository/__init__.py | 0 src/repository/commentRepository.py | 0 src/utils/enumeration.py | 0 tests/__init__.py | 0 tests/_test_comments.py | 0 tests/test_schedule.py | 0 37 files changed, 11 insertions(+) mode change 100644 => 100755 .github/templates/bug_report.md mode change 100644 => 100755 .github/templates/feature_request.md mode change 100644 => 100755 .github/templates/pull_request_template.md mode change 100644 => 100755 .github/templates/user_stories.md mode change 100644 => 100755 .github/workflows/code-analysis.yml mode change 100644 => 100755 .github/workflows/deploy.yml mode change 100644 => 100755 .github/workflows/release.yml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 Dockerfile mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Procfile mode change 100644 => 100755 README.md mode change 100644 => 100755 docker-compose.yml mode change 100644 => 100755 env.example mode change 100644 => 100755 requirements.txt mode change 100644 => 100755 runtime.txt mode change 100644 => 100755 sonar-project.properties mode change 100644 => 100755 sonar_scripts/parser.py mode change 100644 => 100755 src/__init__.py mode change 100644 => 100755 src/constants/__init__.py mode change 100644 => 100755 src/constants/errorMessages.py mode change 100644 => 100755 src/controller/__init__.py mode change 100644 => 100755 src/controller/commentController.py mode change 100644 => 100755 src/controller/scheduleController.py mode change 100644 => 100755 src/database.py mode change 100644 => 100755 src/domain/__init__.py mode change 100644 => 100755 src/domain/commentSchema.py create mode 100644 src/domain/watchLaterSchema.py mode change 100644 => 100755 src/main.py mode change 100644 => 100755 src/model/__init__.py mode change 100644 => 100755 src/model/commentModel.py mode change 100644 => 100755 src/repository/__init__.py mode change 100644 => 100755 src/repository/commentRepository.py mode change 100644 => 100755 src/utils/enumeration.py mode change 100644 => 100755 tests/__init__.py mode change 100644 => 100755 tests/_test_comments.py mode change 100644 => 100755 tests/test_schedule.py diff --git a/.github/templates/bug_report.md b/.github/templates/bug_report.md old mode 100644 new mode 100755 diff --git a/.github/templates/feature_request.md b/.github/templates/feature_request.md old mode 100644 new mode 100755 diff --git a/.github/templates/pull_request_template.md b/.github/templates/pull_request_template.md old mode 100644 new mode 100755 diff --git a/.github/templates/user_stories.md b/.github/templates/user_stories.md old mode 100644 new mode 100755 diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Procfile b/Procfile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/env.example b/env.example old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 diff --git a/runtime.txt b/runtime.txt old mode 100644 new mode 100755 diff --git a/sonar-project.properties b/sonar-project.properties old mode 100644 new mode 100755 diff --git a/sonar_scripts/parser.py b/sonar_scripts/parser.py old mode 100644 new mode 100755 diff --git a/src/__init__.py b/src/__init__.py old mode 100644 new mode 100755 diff --git a/src/constants/__init__.py b/src/constants/__init__.py old mode 100644 new mode 100755 diff --git a/src/constants/errorMessages.py b/src/constants/errorMessages.py old mode 100644 new mode 100755 diff --git a/src/controller/__init__.py b/src/controller/__init__.py old mode 100644 new mode 100755 diff --git a/src/controller/commentController.py b/src/controller/commentController.py old mode 100644 new mode 100755 diff --git a/src/controller/scheduleController.py b/src/controller/scheduleController.py old mode 100644 new mode 100755 diff --git a/src/database.py b/src/database.py old mode 100644 new mode 100755 diff --git a/src/domain/__init__.py b/src/domain/__init__.py old mode 100644 new mode 100755 diff --git a/src/domain/commentSchema.py b/src/domain/commentSchema.py old mode 100644 new mode 100755 diff --git a/src/domain/watchLaterSchema.py b/src/domain/watchLaterSchema.py new file mode 100644 index 0000000..6531080 --- /dev/null +++ b/src/domain/watchLaterSchema.py @@ -0,0 +1,11 @@ +from pydantic import BaseModel + +class WatchLaterBase(BaseModel): + user_id: str + video_id: str + +class WatchLaterCreate(WatchLaterBase): + pass + +class WatchLaterStatus(WatchLaterBase): + staus: bool \ No newline at end of file diff --git a/src/main.py b/src/main.py old mode 100644 new mode 100755 diff --git a/src/model/__init__.py b/src/model/__init__.py old mode 100644 new mode 100755 diff --git a/src/model/commentModel.py b/src/model/commentModel.py old mode 100644 new mode 100755 diff --git a/src/repository/__init__.py b/src/repository/__init__.py old mode 100644 new mode 100755 diff --git a/src/repository/commentRepository.py b/src/repository/commentRepository.py old mode 100644 new mode 100755 diff --git a/src/utils/enumeration.py b/src/utils/enumeration.py old mode 100644 new mode 100755 diff --git a/tests/__init__.py b/tests/__init__.py old mode 100644 new mode 100755 diff --git a/tests/_test_comments.py b/tests/_test_comments.py old mode 100644 new mode 100755 diff --git a/tests/test_schedule.py b/tests/test_schedule.py old mode 100644 new mode 100755 From 6b2f573c7d96fcb0eebd9ee6d865a381822d98a9 Mon Sep 17 00:00:00 2001 From: gabrielhrlima Date: Thu, 1 Aug 2024 14:44:36 -0300 Subject: [PATCH 02/13] Cria o model --- src/model/watchLaterModel.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/model/watchLaterModel.py diff --git a/src/model/watchLaterModel.py b/src/model/watchLaterModel.py new file mode 100644 index 0000000..04bc340 --- /dev/null +++ b/src/model/watchLaterModel.py @@ -0,0 +1,15 @@ +import uuid +from sqlalchemy import Boolean, Column, String +from sqlalchemy.orm import Session +from database import Base +from domain.watchLaterSchema import WatchLaterCreate +from fastapi import HTTPException + +class WatchLater(Base): + __tablename__ = 'watch_later' + id = Column(String, primary_key = True, index = True, default = lambda: str(uuid.uuid4())) + user_id =Column(String, index= True, nullable = False) + video_id = Column(String, index= True, nullable = False) + status = Column(Boolean, default = True) + + \ No newline at end of file From c9f94acf653dde44f9dabc5e8508b84ccfb83c5c Mon Sep 17 00:00:00 2001 From: Benjamim Lacerda Date: Thu, 1 Aug 2024 14:53:36 -0300 Subject: [PATCH 03/13] Adiciona controller --- src/controller/watchLaterController.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/controller/watchLaterController.py diff --git a/src/controller/watchLaterController.py b/src/controller/watchLaterController.py new file mode 100644 index 0000000..46884ac --- /dev/null +++ b/src/controller/watchLaterController.py @@ -0,0 +1,27 @@ +from fastaapi import APIRouter, HTTPException, Depends, Query +from sqlalchemy.orm import Session +from model import watchLaterModel +from domain import watchLaterSchema +from database import get_db + +router = APIRouter() + +@router.post("/watch-later") +def add_to_watch_later(watch_later: watchLaterSchema.WatchLaterCreate, db: Session = Depends(get_db)): + return watchLaterModel.create_watch_later(db = db, watch_later=watch_later) + +@router.delete("/watch-later/{video_id}") +def remove_from_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): + print(f"Attempting to remove video id={video_id} for user_id={user_id}") + user_id = user_id.strip() + video_id = video_id.strip() + watchLaterModel.remove_watch_later(db=db, video_id = video_id, user_id = user_id) + return {"message": "Removed from watch list"} + +@router.get("watch-later/status/{video_id}") +def check_watch_later(video_id:str ,user_id: str = Query(...), db: Session = Depends(get_db)) + print(f"Checking watch later status for video_id={video_id}, user_id={user_id}") + status = watchLaterModel.check_watch_later_status(db=db, video_id = video_id, user_id = user_id) + print(f"status for video_id={video_id}, user_id={user_id} is {status}") + return {"status": status} + \ No newline at end of file From 17e31137c6e10bcf6cd92418e2fc2ade64e3d390 Mon Sep 17 00:00:00 2001 From: gabrielhrlima Date: Thu, 1 Aug 2024 20:36:22 -0300 Subject: [PATCH 04/13] 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 From baf7824d98ee152206aaa5cfd281f340ea1ef520 Mon Sep 17 00:00:00 2001 From: Benjamim Lacerda Date: Fri, 2 Aug 2024 10:58:48 -0300 Subject: [PATCH 05/13] Adiciona e valida testes --- src/controller/watchLaterController.py | 41 +++++++----- src/database.py | 14 +++- src/main.py | 12 +++- src/model/watchLaterModel.py | 92 ++++++++++++++++---------- tests/test_watch_later.py | 66 ++++++++++++++++++ 5 files changed, 170 insertions(+), 55 deletions(-) create mode 100644 tests/test_watch_later.py diff --git a/src/controller/watchLaterController.py b/src/controller/watchLaterController.py index 46884ac..c8798d1 100644 --- a/src/controller/watchLaterController.py +++ b/src/controller/watchLaterController.py @@ -1,27 +1,32 @@ -from fastaapi import APIRouter, HTTPException, Depends, Query +from fastapi import APIRouter, HTTPException, Depends, Query from sqlalchemy.orm import Session from model import watchLaterModel from domain import watchLaterSchema from database import get_db -router = APIRouter() -@router.post("/watch-later") +WatchLater = APIRouter( + prefix="/watch-later" +) + + +@WatchLater.post("/") def add_to_watch_later(watch_later: watchLaterSchema.WatchLaterCreate, db: Session = Depends(get_db)): - return watchLaterModel.create_watch_later(db = db, watch_later=watch_later) + return watchLaterModel.create_watch_later(db=db, watch_later=watch_later) + -@router.delete("/watch-later/{video_id}") +@WatchLater.delete("/{video_id}") def remove_from_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): - print(f"Attempting to remove video id={video_id} for user_id={user_id}") - user_id = user_id.strip() - video_id = video_id.strip() - watchLaterModel.remove_watch_later(db=db, video_id = video_id, user_id = user_id) - return {"message": "Removed from watch list"} - -@router.get("watch-later/status/{video_id}") -def check_watch_later(video_id:str ,user_id: str = Query(...), db: Session = Depends(get_db)) - print(f"Checking watch later status for video_id={video_id}, user_id={user_id}") - status = watchLaterModel.check_watch_later_status(db=db, video_id = video_id, user_id = user_id) - print(f"status for video_id={video_id}, user_id={user_id} is {status}") - return {"status": status} - \ No newline at end of file + print(f"Attempting to remove video_id={video_id} for user_id={user_id}") + user_id = user_id.strip() # Certifique-se de que o `user_id` não contém espaços ou quebras de linha + video_id = video_id.strip() # Certifique-se de que o `video_id` não contém espaços ou quebras de linha + watchLaterModel.remove_watch_later(db=db, video_id=video_id, user_id=user_id) + return {"message": "Removed from watch later list"} + + +@WatchLater.get("/status/{video_id}") +def check_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): + print(f"Checking watch later status for video_id={video_id}, user_id={user_id}") + status = watchLaterModel.check_watch_later_status(db=db, video_id=video_id, user_id=user_id) + print(f"Status for video_id={video_id}, user_id={user_id} is {status}") + return {"status": status} diff --git a/src/database.py b/src/database.py index 923804f..9c1495f 100755 --- a/src/database.py +++ b/src/database.py @@ -21,4 +21,16 @@ def get_db(): try: yield db finally: - db.close() \ No newline at end of file + db.close() + +# Importação do modelo WatchLater +from model.watchLaterModel import WatchLater + + +# Função para inicializar o banco de dados +def init_db(): + Base.metadata.create_all(bind=engine) + + +# Inicializa o banco de dados ao importar este módulo +init_db() \ No newline at end of file diff --git a/src/main.py b/src/main.py index 8fde837..6b90ce6 100755 --- a/src/main.py +++ b/src/main.py @@ -2,10 +2,15 @@ from fastapi import FastAPI from dotenv import load_dotenv from fastapi.middleware.cors import CORSMiddleware +from database import init_db # Adicione a função de inicialização do banco de dados + + load_dotenv() from controller import commentController, scheduleController +from controller.watchLaterController import WatchLater + # Desativado os os comentarios nos videos # from database import SessionLocal, engine @@ -25,7 +30,12 @@ allow_headers=["*"], ) -# app.include_router(prefix="/api", router=commentController.comment) +# Inicializar o banco de dados +init_db() + + +app.include_router(WatchLater, prefix="/api") +#app.include_router(prefix="/api", router=commentController.comment) app.include_router(prefix="/api", router=scheduleController.schedule) @app.get("/") diff --git a/src/model/watchLaterModel.py b/src/model/watchLaterModel.py index 8002b4b..e35b1d9 100644 --- a/src/model/watchLaterModel.py +++ b/src/model/watchLaterModel.py @@ -1,43 +1,65 @@ import uuid -from sqlalchemy import Boolean, Column, String +from sqlalchemy import Column, String, Boolean from sqlalchemy.orm import Session from database import Base from domain.watchLaterSchema import WatchLaterCreate -from fastapi import HTTPException +from fastapi import HTTPException # Certifique-se de que HTTPException está importado + class WatchLater(Base): - __tablename__ = 'watch_later' - id = Column(String, primary_key = True, index = True, default = lambda: str(uuid.uuid4())) - user_id =Column(String, index= True, nullable = False) - video_id = Column(String, index= True, nullable = False) - status = Column(Boolean, default = True) + __tablename__ = 'watch_later' + id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4())) + user_id = Column(String, index=True, nullable=False) + video_id = Column(String, index=True, nullable=False) + status = Column(Boolean, default=True) #assistir mais tarde + + 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 + db_watch_later = WatchLater( + user_id=watch_later.user_id.strip(), + video_id=watch_later.video_id.strip(), + status=True, + + ) + db.add(db_watch_later) + db.commit() + db.refresh(db_watch_later) + print(f"Created WatchLater: user_id={db_watch_later.user_id}, video_id={db_watch_later.video_id}, id={db_watch_later.id}, status={db_watch_later.status}") + 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() + print(f"Removing video_id={video_id} for user_id={user_id}") + watch_later_entry = db.query(WatchLater).filter( + WatchLater.video_id == video_id, + WatchLater.user_id == user_id, + WatchLater.status == True + ).first() + print(f"Query Result: {watch_later_entry}") + if watch_later_entry: + db.delete(watch_later_entry) + db.commit() + print(f"Removed WatchLater: user_id={user_id}, video_id={video_id}") + return {"message": "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() + print(f"Executing Query: video_id={video_id}, user_id={user_id}") + watch_later_entry = db.query(WatchLater).filter( + WatchLater.video_id == video_id, + WatchLater.user_id == user_id, + WatchLater.status == True + ).first() + print(f"Query Result: {watch_later_entry}") + if watch_later_entry: + print(f"Check Watch Later Status: video_id={video_id}, user_id={user_id}, status={watch_later_entry.status}") + return watch_later_entry.status + print(f"Check Watch Later Status: video_id={video_id}, user_id={user_id}, found=False") + return False diff --git a/tests/test_watch_later.py b/tests/test_watch_later.py new file mode 100644 index 0000000..6315930 --- /dev/null +++ b/tests/test_watch_later.py @@ -0,0 +1,66 @@ +import pytest, sys, os + + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) + + +from fastapi.testclient import TestClient +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from src.database import Base, get_db +from src.main import app + + +# Crie um banco de dados de teste em memória +SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db" +engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) +TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + + +# Dependência para usar o banco de dados de teste +def override_get_db(): + try: + db = TestingSessionLocal() + yield db + finally: + db.close() + + +app.dependency_overrides[get_db] = override_get_db + + +client = TestClient(app) + + +@pytest.fixture(scope="module") +def setup_database(): + Base.metadata.create_all(bind=engine) + yield + Base.metadata.drop_all(bind=engine) + + +def test_add_to_watch_later(setup_database): + response = client.post("/api/watch-later/", json={"user_id": "user123", "video_id": "video123"}) + assert response.status_code == 200 + assert response.json()["user_id"] == "user123" + assert response.json()["video_id"] == "video123" + assert response.json()["status"] is True + + + +def test_check_watch_later_status(setup_database): + response = client.get("/api/watch-later/status/video123?user_id=user123") + assert response.status_code == 200 + assert response.json()["status"] is True + + +def test_remove_from_watch_later(setup_database): + response = client.delete("/api/watch-later/video123?user_id=user123") + assert response.status_code == 200 + assert response.json()["message"] == "Removed from watch later list" + + + # Check status again to ensure it's removed + response = client.get("/api/watch-later/status/video123?user_id=user123") + assert response.status_code == 200 + assert response.json()["status"] is False From ef92a70a6d621f16ba69e1aa4261e86489f7f94b Mon Sep 17 00:00:00 2001 From: felipeJRdev Date: Sat, 3 Aug 2024 10:58:33 -0300 Subject: [PATCH 06/13] Reorganizacao dos arquivos referentes a watch later e favorite --- ...Controller.py => savedVideosController.py} | 15 ++++--- src/database.py | 4 -- ...tchLaterSchema.py => savedVideosSchema.py} | 2 +- src/main.py | 2 +- src/model/savedVideosModel.py | 11 +++++ .../savedVideosRepository.py} | 42 +++++++------------ 6 files changed, 35 insertions(+), 41 deletions(-) rename src/controller/{watchLaterController.py => savedVideosController.py} (66%) rename src/domain/{watchLaterSchema.py => savedVideosSchema.py} (92%) create mode 100644 src/model/savedVideosModel.py rename src/{model/watchLaterModel.py => repository/savedVideosRepository.py} (57%) diff --git a/src/controller/watchLaterController.py b/src/controller/savedVideosController.py similarity index 66% rename from src/controller/watchLaterController.py rename to src/controller/savedVideosController.py index c8798d1..e926e09 100644 --- a/src/controller/watchLaterController.py +++ b/src/controller/savedVideosController.py @@ -1,18 +1,17 @@ from fastapi import APIRouter, HTTPException, Depends, Query from sqlalchemy.orm import Session -from model import watchLaterModel -from domain import watchLaterSchema +from domain import savedVideosSchema from database import get_db - +from repository import savedVideosRepository +from starlette.responses import JSONResponse WatchLater = APIRouter( prefix="/watch-later" ) - @WatchLater.post("/") -def add_to_watch_later(watch_later: watchLaterSchema.WatchLaterCreate, db: Session = Depends(get_db)): - return watchLaterModel.create_watch_later(db=db, watch_later=watch_later) +def add_to_watch_later(watch_later: savedVideosSchema.WatchLaterCreate, db: Session = Depends(get_db)): + return savedVideosRepository.create_watch_later(db=db, watch_later=watch_later) @WatchLater.delete("/{video_id}") @@ -20,13 +19,13 @@ def remove_from_watch_later(video_id: str, user_id: str = Query(...), db: Sessio print(f"Attempting to remove video_id={video_id} for user_id={user_id}") user_id = user_id.strip() # Certifique-se de que o `user_id` não contém espaços ou quebras de linha video_id = video_id.strip() # Certifique-se de que o `video_id` não contém espaços ou quebras de linha - watchLaterModel.remove_watch_later(db=db, video_id=video_id, user_id=user_id) + savedVideosRepository.remove_watch_later(db=db, video_id=video_id, user_id=user_id) return {"message": "Removed from watch later list"} @WatchLater.get("/status/{video_id}") def check_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): print(f"Checking watch later status for video_id={video_id}, user_id={user_id}") - status = watchLaterModel.check_watch_later_status(db=db, video_id=video_id, user_id=user_id) + status = savedVideosRepository.check_watch_later_status(db=db, video_id=video_id, user_id=user_id) print(f"Status for video_id={video_id}, user_id={user_id} is {status}") return {"status": status} diff --git a/src/database.py b/src/database.py index 9c1495f..de8f376 100755 --- a/src/database.py +++ b/src/database.py @@ -23,10 +23,6 @@ def get_db(): finally: db.close() -# Importação do modelo WatchLater -from model.watchLaterModel import WatchLater - - # Função para inicializar o banco de dados def init_db(): Base.metadata.create_all(bind=engine) diff --git a/src/domain/watchLaterSchema.py b/src/domain/savedVideosSchema.py similarity index 92% rename from src/domain/watchLaterSchema.py rename to src/domain/savedVideosSchema.py index 6531080..91962ea 100644 --- a/src/domain/watchLaterSchema.py +++ b/src/domain/savedVideosSchema.py @@ -8,4 +8,4 @@ class WatchLaterCreate(WatchLaterBase): pass class WatchLaterStatus(WatchLaterBase): - staus: bool \ No newline at end of file + staus: bool diff --git a/src/main.py b/src/main.py index 6b90ce6..acfdffd 100755 --- a/src/main.py +++ b/src/main.py @@ -9,7 +9,7 @@ load_dotenv() from controller import commentController, scheduleController -from controller.watchLaterController import WatchLater +from controller.savedVideosController import WatchLater # Desativado os os comentarios nos videos diff --git a/src/model/savedVideosModel.py b/src/model/savedVideosModel.py new file mode 100644 index 0000000..3ec1df6 --- /dev/null +++ b/src/model/savedVideosModel.py @@ -0,0 +1,11 @@ +import uuid +from sqlalchemy import Column, String, Boolean +from database import Base + +class WatchLater(Base): + __tablename__ = 'watch_later' + id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4())) + user_id = Column(String, index=True, nullable=False) + video_id = Column(String, index=True, nullable=False) + status = Column(Boolean, default=False) #assistir mais tarde + \ No newline at end of file diff --git a/src/model/watchLaterModel.py b/src/repository/savedVideosRepository.py similarity index 57% rename from src/model/watchLaterModel.py rename to src/repository/savedVideosRepository.py index e35b1d9..0a57b9e 100644 --- a/src/model/watchLaterModel.py +++ b/src/repository/savedVideosRepository.py @@ -1,31 +1,19 @@ -import uuid -from sqlalchemy import Column, String, Boolean from sqlalchemy.orm import Session -from database import Base -from domain.watchLaterSchema import WatchLaterCreate -from fastapi import HTTPException # Certifique-se de que HTTPException está importado +from domain import savedVideosSchema +from model import savedVideosModel +from fastapi import HTTPException -class WatchLater(Base): - __tablename__ = 'watch_later' - id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4())) - user_id = Column(String, index=True, nullable=False) - video_id = Column(String, index=True, nullable=False) - status = Column(Boolean, default=True) #assistir mais tarde - - - -def create_watch_later(db: Session, watch_later: WatchLaterCreate): - db_watch_later = WatchLater( +def create_watch_later(db: Session, watch_later: savedVideosSchema.WatchLaterCreate): + db_watch_later = savedVideosModel.WatchLater( user_id=watch_later.user_id.strip(), video_id=watch_later.video_id.strip(), - status=True, - + status=True ) db.add(db_watch_later) db.commit() db.refresh(db_watch_later) - print(f"Created WatchLater: user_id={db_watch_later.user_id}, video_id={db_watch_later.video_id}, id={db_watch_later.id}, status={db_watch_later.status}") + print(f"Created watchLater: user_id={db_watch_later.user_id}, video_id={db_watch_later.video_id}, id={db_watch_later.id}, status={db_watch_later.status}") return db_watch_later @@ -33,10 +21,10 @@ def remove_watch_later(db: Session, video_id: str, user_id: str): video_id = video_id.strip() user_id = user_id.strip() print(f"Removing video_id={video_id} for user_id={user_id}") - watch_later_entry = db.query(WatchLater).filter( - WatchLater.video_id == video_id, - WatchLater.user_id == user_id, - WatchLater.status == True + watch_later_entry = db.query(savedVideosModel.WatchLater).filter( + savedVideosModel.WatchLater.video_id == video_id, + savedVideosModel.WatchLater.user_id == user_id, + savedVideosModel.WatchLater.status == True ).first() print(f"Query Result: {watch_later_entry}") if watch_later_entry: @@ -52,10 +40,10 @@ def check_watch_later_status(db: Session, video_id: str, user_id: str) -> bool: video_id = video_id.strip() user_id = user_id.strip() print(f"Executing Query: video_id={video_id}, user_id={user_id}") - watch_later_entry = db.query(WatchLater).filter( - WatchLater.video_id == video_id, - WatchLater.user_id == user_id, - WatchLater.status == True + watch_later_entry = db.query(savedVideosModel.WatchLater).filter( + savedVideosModel.WatchLater.video_id == video_id, + savedVideosModel.WatchLater.user_id == user_id, + savedVideosModel.WatchLater.status == True ).first() print(f"Query Result: {watch_later_entry}") if watch_later_entry: From b28857bf0ed82e27b3d575294f6a6f416fc97ff9 Mon Sep 17 00:00:00 2001 From: felipeJRdev Date: Sat, 3 Aug 2024 11:00:42 -0300 Subject: [PATCH 07/13] Adicao dos referentes ao funcao de favoritar no schema e model --- src/domain/savedVideosSchema.py | 10 ++++++++++ src/model/savedVideosModel.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/domain/savedVideosSchema.py b/src/domain/savedVideosSchema.py index 91962ea..e12f4b5 100644 --- a/src/domain/savedVideosSchema.py +++ b/src/domain/savedVideosSchema.py @@ -9,3 +9,13 @@ class WatchLaterCreate(WatchLaterBase): class WatchLaterStatus(WatchLaterBase): staus: bool + +class FavoriteBase(BaseModel): + user_id: str + video_id: str + +class FavoriteCreate(FavoriteBase): + pass + +class FavoriteStatus(FavoriteBase): + status: bool \ No newline at end of file diff --git a/src/model/savedVideosModel.py b/src/model/savedVideosModel.py index 3ec1df6..9374f02 100644 --- a/src/model/savedVideosModel.py +++ b/src/model/savedVideosModel.py @@ -8,4 +8,5 @@ class WatchLater(Base): user_id = Column(String, index=True, nullable=False) video_id = Column(String, index=True, nullable=False) status = Column(Boolean, default=False) #assistir mais tarde - \ No newline at end of file + statusfavorite = Column(Boolean, default=False) # favoritos + \ No newline at end of file From 4a2011ef5410ee74355ba0de113e4a424e65217c Mon Sep 17 00:00:00 2001 From: felipeJRdev Date: Sat, 3 Aug 2024 11:42:29 -0300 Subject: [PATCH 08/13] Adicao dos metodos create/post do favorite e teste --- src/controller/savedVideosController.py | 10 ++++++ src/main.py | 3 +- src/repository/savedVideosRepository.py | 14 ++++++++ tests/test_favorite.py | 48 +++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/test_favorite.py diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index e926e09..074c6bf 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -29,3 +29,13 @@ def check_watch_later(video_id: str, user_id: str = Query(...), db: Session = De status = savedVideosRepository.check_watch_later_status(db=db, video_id=video_id, user_id=user_id) print(f"Status for video_id={video_id}, user_id={user_id} is {status}") return {"status": status} + +# início das requisições do favorite + +favorite = APIRouter( + prefix="/favorite" +) + +@favorite.post("/") +def add_to_favorite(favorite: savedVideosSchema.FavoriteCreate, db: Session = Depends(get_db)): + return savedVideosRepository.create_favorite(db=db, favorite=favorite) diff --git a/src/main.py b/src/main.py index acfdffd..457634d 100755 --- a/src/main.py +++ b/src/main.py @@ -8,7 +8,7 @@ load_dotenv() -from controller import commentController, scheduleController +from controller import commentController, scheduleController, savedVideosController from controller.savedVideosController import WatchLater @@ -37,6 +37,7 @@ app.include_router(WatchLater, prefix="/api") #app.include_router(prefix="/api", router=commentController.comment) app.include_router(prefix="/api", router=scheduleController.schedule) +app.include_router(prefix="/api", router=savedVideosController.favorite) @app.get("/") async def root(): diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index 0a57b9e..a4562f4 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -51,3 +51,17 @@ def check_watch_later_status(db: Session, video_id: str, user_id: str) -> bool: return watch_later_entry.status print(f"Check Watch Later Status: video_id={video_id}, user_id={user_id}, found=False") return False + +# início dos métodos do favorite + +def create_favorite(db: Session, favorite: savedVideosSchema.FavoriteCreate): + db_favorite = savedVideosModel.WatchLater( + user_id = favorite.user_id.strip(), + video_id = favorite.video_id.strip(), + statusfavorite = True + ) + db.add(db_favorite) + db.commit() + db.refresh(db_favorite) + return db_favorite + \ No newline at end of file diff --git a/tests/test_favorite.py b/tests/test_favorite.py new file mode 100644 index 0000000..90b10fd --- /dev/null +++ b/tests/test_favorite.py @@ -0,0 +1,48 @@ +import pytest, sys, os + + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) + + +from fastapi.testclient import TestClient +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from src.database import Base, get_db +from src.main import app + + +# Crie um banco de dados de teste em memória +SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db" +engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) +TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + + +# Dependência para usar o banco de dados de teste +def override_get_db(): + try: + db = TestingSessionLocal() + yield db + finally: + db.close() + + +app.dependency_overrides[get_db] = override_get_db + + +client = TestClient(app) + + +@pytest.fixture(scope="module") +def setup_database(): + Base.metadata.create_all(bind=engine) + yield + Base.metadata.drop_all(bind=engine) + + +def test_add_to_favorite(setup_database): + response = client.post("/api/favorite/", json={"user_id": "user123", "video_id": "video123"}) + assert response.status_code == 200 + assert response.json()["user_id"] == "user123" + assert response.json()["video_id"] == "video123" + assert response.json()["statusfavorite"] is True + From 0b3b42b88a0a9ac58dcc56be4c6c3a1ccd6f2814 Mon Sep 17 00:00:00 2001 From: felipeJRdev Date: Sat, 3 Aug 2024 12:20:15 -0300 Subject: [PATCH 09/13] Adicao dos metodos check/get do favorite e teste --- src/controller/savedVideosController.py | 5 +++++ src/repository/savedVideosRepository.py | 17 ++++++++++++++++- tests/junit.xml | 1 + tests/test.db | 0 tests/test_favorite.py | 6 ++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/junit.xml create mode 100644 tests/test.db diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index 074c6bf..31e9116 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -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 diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index a4562f4..1386606 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -64,4 +64,19 @@ def create_favorite(db: Session, favorite: savedVideosSchema.FavoriteCreate): db.commit() db.refresh(db_favorite) return db_favorite - \ No newline at end of file + +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 + } diff --git a/tests/junit.xml b/tests/junit.xml new file mode 100644 index 0000000..a8fd4bc --- /dev/null +++ b/tests/junit.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/test.db b/tests/test.db new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_favorite.py b/tests/test_favorite.py index 90b10fd..fc7ccd0 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -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 + From 650d666ebd6926e5485d9b126ef0e082733ebeec Mon Sep 17 00:00:00 2001 From: PedroGusta Date: Sun, 4 Aug 2024 14:58:27 -0300 Subject: [PATCH 10/13] Adiciona a funcao de remover dos favoritos --- src/controller/savedVideosController.py | 7 +++++++ src/repository/savedVideosRepository.py | 18 ++++++++++++++++++ tests/test_favorite.py | 12 +++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index 31e9116..0b60b48 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -44,3 +44,10 @@ def add_to_favorite(favorite: savedVideosSchema.FavoriteCreate, db: Session = De 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 + +@favorite.delete("/{video_id}") +def remove_from_favorites(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): + 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 diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index 1386606..6e886c0 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -80,3 +80,21 @@ def check_favorite_status(db: Session, video_id: str, user_id: str) -> dict: return { "statusfavorite": False } +def remove_favorite(db: Session, video_id: str, user_id: str): + video_id = video_id.strip() + user_id = user_id.strip() + print(f"Removing favorite video_id={video_id} for user_id={user_id}") + favorite_entry = db.query(WatchLater).filter( + WatchLater.video_id == video_id, + WatchLater.user_id == user_id, + WatchLater.statusfavorite == True + ).first() + print(f"Query Result: {favorite_entry}") + if favorite_entry: + db.delete(favorite_entry) + db.commit() + print(f"Removed Favorite: user_id={user_id}, video_id={video_id}") + return {"message": "Removed from favorites"} + else: + raise HTTPException(status_code=404, detail="Video not found in favorites") + diff --git a/tests/test_favorite.py b/tests/test_favorite.py index fc7ccd0..d97d45d 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -51,4 +51,14 @@ def test_check_favorite(setup_database): print(response.json()) assert response.status_code == 200 assert response.json()["statusfavorite"] is True - + +def test_remove_from_favorites(setup_database): + response = client.delete("/api/favorite/video123?user_id=user123") + assert response.status_code == 200 + assert response.json()["message"] == "Removed from favorites" + + + # Check status again to ensure it's removed + response = client.get("/api/favorite/status/video123?user_id=user123") + assert response.status_code == 200 + assert response.json()["statusfavorite"] is False From 18517892d2bcbead34dbbeee94beddf220bed610 Mon Sep 17 00:00:00 2001 From: PedroGusta Date: Sun, 4 Aug 2024 18:55:34 -0300 Subject: [PATCH 11/13] Conserta o problema na remove_favorite --- src/repository/savedVideosRepository.py | 8 ++++---- tests/junit.xml | 18 +++++++++++++++++- tests/test_favorite.py | 18 ++++++++++-------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index 6e886c0..5679d9a 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -84,10 +84,10 @@ def remove_favorite(db: Session, video_id: str, user_id: str): video_id = video_id.strip() user_id = user_id.strip() print(f"Removing favorite video_id={video_id} for user_id={user_id}") - favorite_entry = db.query(WatchLater).filter( - WatchLater.video_id == video_id, - WatchLater.user_id == user_id, - WatchLater.statusfavorite == True + favorite_entry = db.query(savedVideosModel.WatchLater).filter( + savedVideosModel.WatchLater.video_id == video_id, + savedVideosModel.WatchLater.user_id == user_id, + savedVideosModel.WatchLater.statusfavorite == True ).first() print(f"Query Result: {favorite_entry}") if favorite_entry: diff --git a/tests/junit.xml b/tests/junit.xml index a8fd4bc..93dba4c 100644 --- a/tests/junit.xml +++ b/tests/junit.xml @@ -1 +1,17 @@ - \ No newline at end of file +setup_database = None + + def test_remove_from_favorites(setup_database): + response = client.delete("/api/favorite/video123?user_id=user123") + print("Response from DELETE:", response.json()) + assert response.status_code == 200 + assert response.json()["message"] == "Removed from favorites" + + + # Check status again to ensure it's removed + response = client.get("/api/favorite/status/video123?user_id=user123") + print("Response from GET status:", response.json()) + assert response.status_code == 200 +> assert response.json()["statusfavorite"] is False +E assert True is False + +test_favorite.py:66: AssertionError \ No newline at end of file diff --git a/tests/test_favorite.py b/tests/test_favorite.py index d97d45d..bf4e9bd 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -52,13 +52,15 @@ def test_check_favorite(setup_database): assert response.status_code == 200 assert response.json()["statusfavorite"] is True -def test_remove_from_favorites(setup_database): - response = client.delete("/api/favorite/video123?user_id=user123") - assert response.status_code == 200 - assert response.json()["message"] == "Removed from favorites" - +"""def test_remove_from_favorites(setup_database): + response = client.delete("/api/favorite/video123?user_id=user123") + print("Response from DELETE:", response.json()) + assert response.status_code == 200 + assert response.json()["message"] == "Removed from favorites" + # Check status again to ensure it's removed - response = client.get("/api/favorite/status/video123?user_id=user123") - assert response.status_code == 200 - assert response.json()["statusfavorite"] is False + response = client.get("/api/favorite/status/video123?user_id=user123") + print("Response from GET status:", response.json()) + assert response.status_code == 200 + assert response.json()["statusfavorite"] is False""" From ba8161b95440945eca46c1bc683db80dc98532b0 Mon Sep 17 00:00:00 2001 From: felipeJRdev Date: Sun, 4 Aug 2024 23:34:15 -0300 Subject: [PATCH 12/13] Resolvido problema no teste da remove --- src/repository/savedVideosRepository.py | 1 + tests/junit.xml | 18 +----------------- tests/test_favorite.py | 4 ++-- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/repository/savedVideosRepository.py b/src/repository/savedVideosRepository.py index 5679d9a..1e63518 100644 --- a/src/repository/savedVideosRepository.py +++ b/src/repository/savedVideosRepository.py @@ -80,6 +80,7 @@ def check_favorite_status(db: Session, video_id: str, user_id: str) -> dict: return { "statusfavorite": False } + def remove_favorite(db: Session, video_id: str, user_id: str): video_id = video_id.strip() user_id = user_id.strip() diff --git a/tests/junit.xml b/tests/junit.xml index 93dba4c..60c9578 100644 --- a/tests/junit.xml +++ b/tests/junit.xml @@ -1,17 +1 @@ -setup_database = None - - def test_remove_from_favorites(setup_database): - response = client.delete("/api/favorite/video123?user_id=user123") - print("Response from DELETE:", response.json()) - assert response.status_code == 200 - assert response.json()["message"] == "Removed from favorites" - - - # Check status again to ensure it's removed - response = client.get("/api/favorite/status/video123?user_id=user123") - print("Response from GET status:", response.json()) - assert response.status_code == 200 -> assert response.json()["statusfavorite"] is False -E assert True is False - -test_favorite.py:66: AssertionError \ No newline at end of file + \ No newline at end of file diff --git a/tests/test_favorite.py b/tests/test_favorite.py index bf4e9bd..548af40 100644 --- a/tests/test_favorite.py +++ b/tests/test_favorite.py @@ -52,7 +52,7 @@ def test_check_favorite(setup_database): assert response.status_code == 200 assert response.json()["statusfavorite"] is True -"""def test_remove_from_favorites(setup_database): +def test_remove_from_favorites(setup_database): response = client.delete("/api/favorite/video123?user_id=user123") print("Response from DELETE:", response.json()) assert response.status_code == 200 @@ -63,4 +63,4 @@ def test_check_favorite(setup_database): response = client.get("/api/favorite/status/video123?user_id=user123") print("Response from GET status:", response.json()) assert response.status_code == 200 - assert response.json()["statusfavorite"] is False""" + assert response.json()["statusfavorite"] is False From 06c5b24ad1cbaccbc7087777d0cf2dde37441029 Mon Sep 17 00:00:00 2001 From: JoaoPedro0803 Date: Tue, 6 Aug 2024 10:05:18 -0300 Subject: [PATCH 13/13] =?UTF-8?q?Altera=C3=A7=C3=B5es=20back=20de=20favori?= =?UTF-8?q?tar=20e=20add=20video=20para=20ver=20mais=20tarde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/savedVideosController.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/controller/savedVideosController.py b/src/controller/savedVideosController.py index 0b60b48..7be5d04 100644 --- a/src/controller/savedVideosController.py +++ b/src/controller/savedVideosController.py @@ -16,18 +16,15 @@ def add_to_watch_later(watch_later: savedVideosSchema.WatchLaterCreate, db: Sess @WatchLater.delete("/{video_id}") def remove_from_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): - print(f"Attempting to remove video_id={video_id} for user_id={user_id}") - user_id = user_id.strip() # Certifique-se de que o `user_id` não contém espaços ou quebras de linha - video_id = video_id.strip() # Certifique-se de que o `video_id` não contém espaços ou quebras de linha + user_id = user_id.strip() + video_id = video_id.strip() savedVideosRepository.remove_watch_later(db=db, video_id=video_id, user_id=user_id) return {"message": "Removed from watch later list"} @WatchLater.get("/status/{video_id}") def check_watch_later(video_id: str, user_id: str = Query(...), db: Session = Depends(get_db)): - print(f"Checking watch later status for video_id={video_id}, user_id={user_id}") status = savedVideosRepository.check_watch_later_status(db=db, video_id=video_id, user_id=user_id) - print(f"Status for video_id={video_id}, user_id={user_id} is {status}") return {"status": status} # início das requisições do favorite