diff --git a/endpoints/aiderman.post.py b/endpoints/aiderman.post.py new file mode 100644 index 0000000..0382ee4 --- /dev/null +++ b/endpoints/aiderman.post.py @@ -0,0 +1,27 @@ +```python +from fastapi import APIRouter, HTTPException +from typing import List +from models.book import Book + +router = APIRouter() +books = [] # In-memory storage + +@router.post("/aiderman", status_code=201) +async def save_books(book_list: List[Book]): + """Save a list of books to the database""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + books.extend(book_list) + + return { + "method": "POST", + "_verb": "post", + "message": "Books saved successfully", + "books_saved": len(book_list) + } +``` + +This endpoint accepts a list of `Book` objects in the request body and saves them to an in-memory list called `books`. It returns a JSON response with the number of books saved and the required method metadata. + +Ensure that the `Book` model is defined in `models/book.py` with the necessary fields, and imported correctly in this file. \ No newline at end of file