35 lines
828 B
Python
35 lines
828 B
Python
from fastapi import APIRouter, HTTPException
|
|
import uuid
|
|
|
|
books = [] # In-memory storage
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/learn")
|
|
async def generate_book(
|
|
title: str = "Sample Book",
|
|
author: str = "Default Author",
|
|
genre: str = "Fiction"
|
|
):
|
|
"""Demo book generation endpoint"""
|
|
if any(b["title"] == title 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,
|
|
"genre": genre,
|
|
"disabled": False
|
|
})
|
|
|
|
return {
|
|
"message": "Book created successfully",
|
|
"book_id": book_id,
|
|
"title": title,
|
|
"next_steps": [
|
|
"Add chapters (demo)",
|
|
"Complete book details"
|
|
]
|
|
} |