Update code in endpoints/aiderman.post.py
This commit is contained in:
parent
83f3e74cc5
commit
4a11f6a1df
35
endpoints/aiderman.post.py
Normal file
35
endpoints/aiderman.post.py
Normal file
@ -0,0 +1,35 @@
|
||||
```python
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
games = [] # In-memory storage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/aiderman")
|
||||
async def save_games(
|
||||
games_list: list[str]
|
||||
):
|
||||
"""Save list of games to database"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
for game in games_list:
|
||||
games.append(game)
|
||||
|
||||
return {
|
||||
"message": "Games saved successfully",
|
||||
"games": games_list,
|
||||
"method": "POST",
|
||||
"_verb": "post"
|
||||
}
|
||||
```
|
||||
|
||||
This endpoint follows the provided guidelines:
|
||||
|
||||
1. It uses the `@router.post` decorator for the `/aiderman` path.
|
||||
2. It accepts a list of game strings as the `games_list` parameter.
|
||||
3. It validates that the request method is POST, raising a 405 error otherwise.
|
||||
4. It iterates through the `games_list` and appends each game to the `games` list (in-memory storage).
|
||||
5. It returns a response dictionary with the required fields: "message", "games" (the input list), "method", and "_verb".
|
||||
|
||||
The response format matches the provided examples, maintaining the structure and nesting levels. The code also follows the import order, decorator style, parameter naming, and docstring conventions from the examples.
|
Loading…
x
Reference in New Issue
Block a user