uso fixo de json e troca do banco para postgresql
This commit is contained in:
Binary file not shown.
@@ -27,10 +27,10 @@ def read_games(skip: int = 0, limit: int = 100, genre: Optional[str] = None, pla
|
||||
query = db.query(Game)
|
||||
|
||||
if genre:
|
||||
query = query.filter(Game.genres.cast(String).ilike(f'%"{genre}"%'))
|
||||
query = query.filter(Game.genres.contains([genre]))
|
||||
|
||||
if platform:
|
||||
query = query.filter(Game.platforms.cast(String).ilike(f'%"{platform}"%'))
|
||||
query = query.filter(Game.platforms.contains([platform]))
|
||||
|
||||
games = query.offset(skip).limit(limit).all()
|
||||
data = [GameResponse.model_validate(g).model_dump() for g in games]
|
||||
@@ -47,7 +47,7 @@ def create_game(game: GameCreate, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=400, detail="Um jogo com este título/slug já existe.")
|
||||
|
||||
# Cria o modelo no DB
|
||||
game_data = game.model_dump()
|
||||
game_data = game.model_dump(mode='json')
|
||||
db_game = Game(**game_data, slug=slug)
|
||||
|
||||
db.add(db_game)
|
||||
@@ -74,7 +74,7 @@ def update_game(id: str, game: GameUpdate, db: Session = Depends(get_db)):
|
||||
if not db_game:
|
||||
raise HTTPException(status_code=404, detail="Jogo não encontrado.")
|
||||
|
||||
update_data = game.model_dump(exclude_unset=True)
|
||||
update_data = game.model_dump(mode='json', exclude_unset=True)
|
||||
|
||||
if "title" in update_data:
|
||||
new_slug = generate_slug(update_data["title"])
|
||||
|
||||
Reference in New Issue
Block a user