correções na validação de jwt e na requisição POST
This commit is contained in:
@@ -23,8 +23,8 @@ def generate_slug(title: str) -> str:
|
|||||||
text = re.sub(r'-+', '-', text).strip('-')
|
text = re.sub(r'-+', '-', text).strip('-')
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@router.get("/", response_model=StandardResponse)
|
@router.get("", response_model=StandardResponse)
|
||||||
def read_games(skip: int = 0, limit: int = 100, genre: Optional[str] = None, platform: Optional[str] = None, db: Session = Depends(get_db)):
|
def read_games(skip: int = 0, limit: int = 100, genre: Optional[str] = None, platform: Optional[str] = None, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
|
||||||
query = db.query(Game)
|
query = db.query(Game)
|
||||||
|
|
||||||
if genre:
|
if genre:
|
||||||
@@ -38,7 +38,7 @@ def read_games(skip: int = 0, limit: int = 100, genre: Optional[str] = None, pla
|
|||||||
|
|
||||||
return {"success": True, "message": "Lista de jogos", "data": data}
|
return {"success": True, "message": "Lista de jogos", "data": data}
|
||||||
|
|
||||||
@router.post("/", response_model=StandardResponse, status_code=status.HTTP_201_CREATED)
|
@router.post("", response_model=StandardResponse, status_code=status.HTTP_201_CREATED)
|
||||||
def create_game(game: GameCreate, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
|
def create_game(game: GameCreate, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
|
||||||
slug = generate_slug(game.title)
|
slug = generate_slug(game.title)
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ def create_game(game: GameCreate, db: Session = Depends(get_db), current_user: U
|
|||||||
return {"success": True, "message": "Jogo criado com sucesso", "data": data}
|
return {"success": True, "message": "Jogo criado com sucesso", "data": data}
|
||||||
|
|
||||||
@router.get("/{id_ou_slug}", response_model=StandardResponse)
|
@router.get("/{id_ou_slug}", response_model=StandardResponse)
|
||||||
def read_game(id_ou_slug: str, db: Session = Depends(get_db)):
|
def read_game(id_ou_slug: str, db: Session = Depends(get_db), current_user: UserAuth = Depends(get_current_user)):
|
||||||
if id_ou_slug.isdigit():
|
if id_ou_slug.isdigit():
|
||||||
db_game = db.query(Game).filter(Game.id == int(id_ou_slug)).first()
|
db_game = db.query(Game).filter(Game.id == int(id_ou_slug)).first()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, Depends
|
||||||
|
from app.core.security import get_current_user, UserAuth
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.api.v1.api import api_router
|
from app.api.v1.api import api_router
|
||||||
from app.db.database import Base, engine
|
from app.db.database import Base, engine
|
||||||
@@ -14,5 +15,5 @@ app = FastAPI(
|
|||||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def root():
|
def root(current_user: UserAuth = Depends(get_current_user)):
|
||||||
return {"message": "Bem-vindo ao Microsserviço de Catálogo do GameVerse"}
|
return {"message": "Bem-vindo ao Microsserviço de Catálogo do GameVerse"}
|
||||||
|
|||||||
Reference in New Issue
Block a user