From cc2c11a0d37a7b62e8e4c8485c1478853f44f374 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 11:16:47 +0100 Subject: [PATCH] Update code in endpoints/aiderman.post.py --- endpoints/aiderman.post.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 endpoints/aiderman.post.py 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