From 65acde3777b14daaa764fbbcff88b00285bbcefd Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 21 Mar 2025 07:24:31 +0000 Subject: [PATCH] Update code in endpoints/books.post.py --- endpoints/books.post.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/endpoints/books.post.py b/endpoints/books.post.py index e69de29..6945624 100644 --- a/endpoints/books.post.py +++ b/endpoints/books.post.py @@ -0,0 +1,35 @@ +from fastapi import APIRouter, HTTPException +import uuid + +books = [] # In-memory storage + +router = APIRouter() + +@router.post("/books") +async def add_book( + title: str = "Sample Book", + author: str = "John Doe", + isbn: str = "1234567890" +): + """Add book endpoint""" + if any(b["isbn"] == isbn for b in books): + raise HTTPException(status_code=400, detail="Book already exists") + + book_id = str(uuid.uuid4()) + books.append({ + "id": book_id, + "title": title, + "author": author, + "isbn": isbn, + "disabled": False + }) + + return { + "message": "Book added successfully", + "book_id": book_id, + "title": title, + "next_steps": [ + "Add to catalog", + "Update inventory" + ] + } \ No newline at end of file