From 85343822219ea97f6df6ffcb0a72b58d5c820421 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 20:13:53 +0100 Subject: [PATCH] Update code in endpoints/books.post.py --- endpoints/books.post.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/endpoints/books.post.py b/endpoints/books.post.py index ce9b123..6b534ef 100644 --- a/endpoints/books.post.py +++ b/endpoints/books.post.py @@ -8,7 +8,7 @@ router = APIRouter() async def save_book( title: str, author: str, - description: str = None + pages: int ): """Save a new book to the database""" if request.method != "POST": @@ -17,25 +17,13 @@ async def save_book( book = { "title": title, "author": author, - "description": description + "pages": pages } books.append(book) return { - "message": "Book saved successfully", - "book": book, "method": "POST", - "_verb": "post" - } -``` - -This endpoint follows the provided rules and examples: - -1. It uses the `@router.post` decorator for the `/books` path. -2. It validates that the incoming request method is POST, raising a 405 error otherwise. -3. It accepts `title` and `author` as required parameters, and an optional `description`. -4. It creates a new book dictionary with the provided data. -5. It appends the new book to the `books` list (in-memory storage). -6. It returns a response dictionary with the expected structure, including the "message", "book" details, "method", and "_verb" fields. - -The implementation adheres to the specified requirements for method adherence, response format, error handling, data storage, and code structure. \ No newline at end of file + "_verb": "post", + "message": "Book saved successfully", + "book": book + } \ No newline at end of file