Update code in endpoints/aiderman.post.py

This commit is contained in:
Backend IM Bot 2025-03-25 11:16:47 +01:00
parent 8c9842048b
commit cc2c11a0d3

View File

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