implementação da validação por jwt

This commit is contained in:
2026-05-28 09:46:53 -05:00
parent f148d430b3
commit a4cbc28d1d
6 changed files with 211 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import unicodedata
from app.schemas.game import GameCreate, GameUpdate, GameResponse, StandardResponse
from app.models.game import Game
from app.db.database import get_db
from app.core.security import get_current_user, UserAuth
router = APIRouter()
@@ -38,7 +39,7 @@ def read_games(skip: int = 0, limit: int = 100, genre: Optional[str] = None, pla
return {"success": True, "message": "Lista de jogos", "data": data}
@router.post("/", response_model=StandardResponse, status_code=status.HTTP_201_CREATED)
def create_game(game: GameCreate, db: Session = Depends(get_db)):
def create_game(game: GameCreate, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
slug = generate_slug(game.title)
# Verifica se já existe um jogo com esse slug
@@ -71,7 +72,7 @@ def read_game(id_ou_slug: str, db: Session = Depends(get_db)):
return {"success": True, "message": "Detalhes do jogo", "data": data}
@router.patch("/{id}", response_model=StandardResponse)
def update_game(id: int, game: GameUpdate, db: Session = Depends(get_db)):
def update_game(id: int, game: GameUpdate, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
db_game = db.query(Game).filter(Game.id == id).first()
if not db_game:
@@ -98,7 +99,7 @@ def update_game(id: int, game: GameUpdate, db: Session = Depends(get_db)):
return {"success": True, "message": "Jogo atualizado com sucesso", "data": data}
@router.delete("/{id_ou_slug}", response_model=StandardResponse)
def delete_game(id_ou_slug: str, db: Session = Depends(get_db)):
def delete_game(id_ou_slug: str, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
if id_ou_slug.isdigit():
db_game = db.query(Game).filter(Game.id == int(id_ou_slug)).first()
else: