Update code in endpoints/aider.post.py

This commit is contained in:
Backend IM Bot 2025-03-25 10:21:18 +01:00
parent 20f75765e3
commit 83f3e74cc5

34
endpoints/aider.post.py Normal file
View File

@ -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.