Update code in endpoints/books.post.py

This commit is contained in:
Backend IM Bot 2025-03-21 07:24:31 +00:00
parent 04912cdcb0
commit 65acde3777

View File

@ -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"
]
}