Update code in endpoints/books.post.py
This commit is contained in:
parent
04912cdcb0
commit
65acde3777
@ -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"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user