diff --git a/repos/games-xxwif7/repos/games-xxwif7/endpoints/footb.post.py b/repos/games-xxwif7/repos/games-xxwif7/endpoints/footb.post.py new file mode 100644 index 0000000..39cdc23 --- /dev/null +++ b/repos/games-xxwif7/repos/games-xxwif7/endpoints/footb.post.py @@ -0,0 +1,67 @@ +```python +from typing import List +from pydantic import BaseModel, Field +from sqlalchemy import Column, Integer, String, Boolean +from database import Base + +# Game Model + + + id = Column(Integer, primary_key=True, index=True) + name = Column(String) + description = Column(String) + is_active = Column(Boolean, default=True) + +# Game Schema + + +class GameCreate(GameBase): + pass + +class GameUpdate(GameBase): + is_active: bool = Field(default=True) + +class GameOut(GameBase): + id: int + is_active: bool + + class Config: + orm_mode = True + +# In-memory storage +games = [] + +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +@router.post("/footb", status_code=201) +async def create_game(game: GameCreate): + """Create a new game""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + new_game = Game(**game.dict()) + games.append(new_game) + + return { + "method": "POST", + "_verb": "post", + "message": "Game created successfully", + "game": GameOut.from_orm(new_game) + } + +@router.get("/footb") +async def get_games(): + """Get all active games""" + if request.method != "GET": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + active_games = [GameOut.from_orm(game) for game in games if game.is_active] + + return { + "method": "GET", + "_verb": "get", + "games": active_games + } +``` \ No newline at end of file