diff --git a/endpoints/aiderman.post.py b/endpoints/aiderman.post.py new file mode 100644 index 0000000..df4165f --- /dev/null +++ b/endpoints/aiderman.post.py @@ -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. \ No newline at end of file