From bf2dd4ec75b6993ffccae1fabd4b718f6cb50381 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 06:43:19 +0100 Subject: [PATCH] Update code in endpoints/sports.post.py --- endpoints/sports.post.py | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 endpoints/sports.post.py diff --git a/endpoints/sports.post.py b/endpoints/sports.post.py new file mode 100644 index 0000000..4c49e7c --- /dev/null +++ b/endpoints/sports.post.py @@ -0,0 +1,44 @@ +from fastapi import APIRouter, HTTPException +import uuid + +games = [] # In-memory storage + +router = APIRouter() + +@router.post("/sports") +async def save_game( + name: str, + description: str, + category: str +): + """Save a new game to the database""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + game_id = str(uuid.uuid4()) + new_game = { + "id": game_id, + "name": name, + "description": description, + "category": category + } + games.append(new_game) + + return { + "method": "POST", + "_verb": "post", + "message": "Game saved successfully", + "game_id": game_id + } + +@router.get("/sports") +async def get_games(): + """Fetch all games from the database""" + if request.method != "GET": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + return { + "method": "GET", + "_verb": "get", + "games": games + } \ No newline at end of file