From 636e34dbf0740e13971ee311549e1560c34705de Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 08:41:41 +0100 Subject: [PATCH] Update code in endpoints/footballing.post.py --- .../endpoints/footballing.post.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 repos/kerza-ng8deg/endpoints/footballing.post.py diff --git a/repos/kerza-ng8deg/endpoints/footballing.post.py b/repos/kerza-ng8deg/endpoints/footballing.post.py new file mode 100644 index 0000000..7ce20aa --- /dev/null +++ b/repos/kerza-ng8deg/endpoints/footballing.post.py @@ -0,0 +1,60 @@ +```python +from typing import List +from pydantic import BaseModel, Field +from uuid import uuid4 +from datetime import datetime + +# Database storage +games = [] + +# Pydantic models + + +class GameModel(GameBase): + id: str = Field(default_factory=lambda: str(uuid4())) + created_at: datetime = Field(default_factory=datetime.now) + updated_at: datetime = Field(default_factory=datetime.now) + + class Config: + orm_mode = True + +class GameList(BaseModel): + games: List[GameModel] + +# Routers +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +@router.post("/footballing", status_code=201) +async def create_game(game: GameBase): + """Save a new game to the database""" + if request.method != "POST": + raise HTTPException(status_code=405, detail={ + "message": "Method Not Allowed", + "method": "POST", + "_verb": "post" + }) + + new_game = GameModel(**game.dict()) + games.append(new_game) + + return { + "message": "Game created successfully", + "game": new_game, + "method": "POST", + "_verb": "post" + } + +@router.get("/footballing", response_model=GameList) +async def get_games(): + """Fetch all games from the database""" + if request.method != "GET": + raise HTTPException(status_code=405, detail={ + "message": "Method Not Allowed", + "method": "GET", + "_verb": "get" + }) + + return {"games": games} +``` \ No newline at end of file