diff --git a/app/api/v1/endpoints/__pycache__/games.cpython-311.pyc b/app/api/v1/endpoints/__pycache__/games.cpython-311.pyc index 488cfb6..2936832 100644 Binary files a/app/api/v1/endpoints/__pycache__/games.cpython-311.pyc and b/app/api/v1/endpoints/__pycache__/games.cpython-311.pyc differ diff --git a/app/api/v1/endpoints/games.py b/app/api/v1/endpoints/games.py index fdeaa56..0b52a51 100644 --- a/app/api/v1/endpoints/games.py +++ b/app/api/v1/endpoints/games.py @@ -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"]) diff --git a/app/models/__pycache__/game.cpython-311.pyc b/app/models/__pycache__/game.cpython-311.pyc index 9432483..7e0b405 100644 Binary files a/app/models/__pycache__/game.cpython-311.pyc and b/app/models/__pycache__/game.cpython-311.pyc differ diff --git a/app/models/game.py b/app/models/game.py index 2cabe14..90f3bb8 100644 --- a/app/models/game.py +++ b/app/models/game.py @@ -1,4 +1,5 @@ -from sqlalchemy import Column, String, Boolean, JSON +from sqlalchemy import Column, String, Boolean +from sqlalchemy.dialects.postgresql import JSONB from app.db.database import Base import uuid @@ -12,9 +13,8 @@ class Game(Base): developer = Column(String) active = Column(Boolean, default=True) - # Usando JSON para simplificar arrays no MVP conforme os requisitos. - # Em um banco relacional robusto, genres e platforms seriam tabelas M:N. - genres = Column(JSON) - platforms = Column(JSON) - images = Column(JSON) - system_requirements = Column(JSON) + # Usando JSONB para melhor performance e suporte a buscas nativas no PostgreSQL + genres = Column(JSONB) + platforms = Column(JSONB) + images = Column(JSONB) + system_requirements = Column(JSONB)