35 lines
791 B
Python
35 lines
791 B
Python
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"
|
|
]
|
|
} |