From 7c259b04173d7f8f910704851004c52a2e075ec5 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 09:22:19 +0100 Subject: [PATCH] Update code in endpoints/football.post.py --- endpoints/football.post.py | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 endpoints/football.post.py diff --git a/endpoints/football.post.py b/endpoints/football.post.py new file mode 100644 index 0000000..c9552b0 --- /dev/null +++ b/endpoints/football.post.py @@ -0,0 +1,69 @@ +```python +from typing import List, Optional +from pydantic import BaseModel, Field +from datetime import datetime + +# Models + + +class GameCreate(GameBase): + pass + +class GameUpdate(GameBase): + pass + +class GameInDBBase(GameBase): + id: int + created_at: datetime + updated_at: datetime + + class Config: + orm_mode = True + +class Game(GameInDBBase): + pass + +class GameInDB(GameInDBBase): + pass + +# In-memory storage +games = [] + +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +@router.post("/football", response_model=Game) +async def create_game(game: GameCreate): + """Save a new game to the database""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + new_game = Game( + name=game.name, + description=game.description, + release_date=game.release_date, + platform=game.platform, + created_at=datetime.now(), + updated_at=datetime.now() + ) + games.append(new_game) + + response = { + "message": "Game created successfully", + "game": new_game, + "method": "POST", + "_verb": "post" + } + return response + +@router.get("/football", response_model=List[Game]) +async def get_games(): + """Fetch all games from the database""" + response = { + "games": games, + "method": "GET", + "_verb": "get" + } + return response +``` \ No newline at end of file