41 lines
1014 B
Python
41 lines
1014 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
import uuid
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/books")
|
|
async def create_book(
|
|
title: str,
|
|
author: str,
|
|
isbn: str = None,
|
|
description: str = None
|
|
):
|
|
"""Create a new book entry"""
|
|
book_id = str(uuid.uuid4())
|
|
|
|
if isbn in [book.get('isbn') for book in fake_users_db.get('books', [])]:
|
|
raise HTTPException(status_code=400, detail="Book with this ISBN already exists")
|
|
|
|
new_book = {
|
|
"id": book_id,
|
|
"title": title,
|
|
"author": author,
|
|
"isbn": isbn,
|
|
"description": description
|
|
}
|
|
|
|
if 'books' not in fake_users_db:
|
|
fake_users_db['books'] = []
|
|
|
|
fake_users_db['books'].append(new_book)
|
|
|
|
return {
|
|
"message": "Book created successfully",
|
|
"book_id": book_id,
|
|
"data": new_book,
|
|
"metadata": {
|
|
"timestamp": "demo_timestamp",
|
|
"version": "1.0"
|
|
}
|
|
} |