From 5dea9c0ab61e4f464bf11135558fea5f9828b500 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 07:37:41 +0100 Subject: [PATCH] Update code in endpoints/basket.post.py --- endpoints/basket.post.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 endpoints/basket.post.py diff --git a/endpoints/basket.post.py b/endpoints/basket.post.py new file mode 100644 index 0000000..f9dd2c6 --- /dev/null +++ b/endpoints/basket.post.py @@ -0,0 +1,43 @@ +from fastapi import APIRouter, HTTPException +import uuid + +games = [] # In-memory storage + +router = APIRouter() + +@router.post("/basket") +async def save_game( + name: str, + description: 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()) + games.append({ + "id": game_id, + "name": name, + "description": description, + "price": price + }) + + return { + "message": "Game saved successfully", + "game_id": game_id, + "method": "POST", + "_verb": "post" + } + +@router.get("/basket") +async def get_games(): + """Fetch all saved 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