From f12a422f6e036920ed6efe74ca28e943aecd8c0f Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 06:37:28 +0100 Subject: [PATCH] Update code in endpoints/game.post.py --- endpoints/game.post.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 endpoints/game.post.py diff --git a/endpoints/game.post.py b/endpoints/game.post.py new file mode 100644 index 0000000..ae61b26 --- /dev/null +++ b/endpoints/game.post.py @@ -0,0 +1,46 @@ +from fastapi import APIRouter, HTTPException +import uuid + +games = [] # In-memory storage + +router = APIRouter() + +@router.post("/game") +async def save_game( + game_name: str, + developer: str, + genre: str, + price: float +): + """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()) + game = { + "id": game_id, + "name": game_name, + "developer": developer, + "genre": genre, + "price": price + } + games.append(game) + + return { + "message": "Game saved successfully", + "game_id": game_id, + "method": "POST", + "_verb": "post" + } + +@router.get("/games") +async def get_games(): + """Fetch all games from the database""" + if request.method != "GET": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + return { + "games": games, + "method": "GET", + "_verb": "get" + } \ No newline at end of file