criação inicial do corpo do projeto
This commit is contained in:
5
app/api/v1/api.py
Normal file
5
app/api/v1/api.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
from app.api.v1.endpoints import games
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(games.router, prefix="/catalog/games", tags=["games"])
|
||||
28
app/api/v1/endpoints/games.py
Normal file
28
app/api/v1/endpoints/games.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
|
||||
from app.schemas.game import GameCreate, GameUpdate, GameResponse, StandardResponse
|
||||
from app.db.database import get_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@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)):
|
||||
# Lógica de listagem e filtragem será implementada aqui
|
||||
return {"success": True, "message": "Lista de jogos", "data": []}
|
||||
|
||||
@router.post("/", response_model=StandardResponse, status_code=status.HTTP_201_CREATED)
|
||||
def create_game(game: GameCreate, db: Session = Depends(get_db)):
|
||||
# Lógica de criação será implementada aqui
|
||||
return {"success": True, "message": "Jogo criado com sucesso", "data": {}}
|
||||
|
||||
@router.get("/{id_ou_slug}", response_model=StandardResponse)
|
||||
def read_game(id_ou_slug: str, db: Session = Depends(get_db)):
|
||||
# Lógica de leitura de um único jogo será implementada aqui
|
||||
return {"success": True, "message": "Detalhes do jogo", "data": {}}
|
||||
|
||||
@router.patch("/{id}", response_model=StandardResponse)
|
||||
def update_game(id: str, game: GameUpdate, db: Session = Depends(get_db)):
|
||||
# Lógica de atualização parcial será implementada aqui
|
||||
return {"success": True, "message": "Jogo atualizado com sucesso", "data": {}}
|
||||
12
app/core/config.py
Normal file
12
app/core/config.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
class Settings(BaseSettings):
|
||||
PROJECT_NAME: str = "Microsserviço de Catálogo de Jogos"
|
||||
API_V1_STR: str = "/api/v1"
|
||||
DATABASE_URL: str
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
settings = Settings()
|
||||
16
app/db/database.py
Normal file
16
app/db/database.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from app.core.config import settings
|
||||
|
||||
engine = create_engine(settings.DATABASE_URL)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
18
app/main.py
Normal file
18
app/main.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import FastAPI
|
||||
from app.core.config import settings
|
||||
from app.api.v1.api import api_router
|
||||
from app.db.database import Base, engine
|
||||
|
||||
# Cria as tabelas do banco de dados (idealmente usaríamos Alembic em produção)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.PROJECT_NAME,
|
||||
openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
||||
)
|
||||
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
return {"message": "Bem-vindo ao Microsserviço de Catálogo do GameVerse"}
|
||||
20
app/models/game.py
Normal file
20
app/models/game.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from sqlalchemy import Column, String, Boolean, JSON
|
||||
from app.db.database import Base
|
||||
import uuid
|
||||
|
||||
class Game(Base):
|
||||
__tablename__ = "games"
|
||||
|
||||
id = Column(String, primary_key=True, default=lambda: f"gv-{uuid.uuid4().hex[:8]}")
|
||||
title = Column(String, index=True, nullable=False)
|
||||
slug = Column(String, unique=True, index=True, nullable=False)
|
||||
description = Column(String)
|
||||
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)
|
||||
46
app/schemas/game.py
Normal file
46
app/schemas/game.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from pydantic import BaseModel, HttpUrl
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
class GameImages(BaseModel):
|
||||
thumbnail: Optional[HttpUrl] = None
|
||||
header: Optional[HttpUrl] = None
|
||||
|
||||
class SystemRequirements(BaseModel):
|
||||
cpu: Optional[str] = None
|
||||
gpu: Optional[str] = None
|
||||
ram: Optional[str] = None
|
||||
|
||||
class GameBase(BaseModel):
|
||||
title: str
|
||||
description: str
|
||||
genres: List[str]
|
||||
platforms: List[str]
|
||||
developer: str
|
||||
images: Optional[GameImages] = None
|
||||
system_requirements: Optional[SystemRequirements] = None
|
||||
active: bool = True
|
||||
|
||||
class GameCreate(GameBase):
|
||||
pass
|
||||
|
||||
class GameUpdate(BaseModel):
|
||||
title: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
genres: Optional[List[str]] = None
|
||||
platforms: Optional[List[str]] = None
|
||||
developer: Optional[str] = None
|
||||
images: Optional[GameImages] = None
|
||||
system_requirements: Optional[SystemRequirements] = None
|
||||
active: Optional[bool] = None
|
||||
|
||||
class GameResponse(GameBase):
|
||||
id: str
|
||||
slug: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class StandardResponse(BaseModel):
|
||||
success: bool
|
||||
message: str
|
||||
data: Optional[Any] = None
|
||||
Reference in New Issue
Block a user