From 83f3e74cc55bc8e41d7a8ea2b12c1fbe863a1716 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 10:21:18 +0100 Subject: [PATCH] Update code in endpoints/aider.post.py --- endpoints/aider.post.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 endpoints/aider.post.py diff --git a/endpoints/aider.post.py b/endpoints/aider.post.py new file mode 100644 index 0000000..4f32501 --- /dev/null +++ b/endpoints/aider.post.py @@ -0,0 +1,34 @@ +```python +from fastapi import APIRouter, HTTPException +import uuid + +games = [] # In-memory storage + +router = APIRouter() + +@router.post("/games") +async def save_games( + games_list: list[str] +): + """Save a list of games to the database""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + for game in games_list: + game_id = str(uuid.uuid4()) + games.append({ + "id": game_id, + "name": game + }) + + return { + "message": "Games saved successfully", + "games_saved": len(games_list), + "method": "POST", + "_verb": "post" + } +``` + +This endpoint accepts a list of game names as input, generates a unique ID for each game, and saves them to an in-memory list called `games`. It returns a JSON response with a success message, the number of games saved, and the HTTP method metadata as per the requirements. + +Note: This implementation uses an in-memory list for demonstration purposes. In a real-world scenario, you would likely use a database or other persistent storage mechanism. \ No newline at end of file