32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from pydantic import BaseModel, Field
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., description="Book title")
|
|
author: str = Field(..., description="Book author")
|
|
description: Optional[str] = Field(None, description="Book description")
|
|
page_count: Optional[int] = Field(None, description="Number of pages")
|
|
published_date: Optional[datetime] = Field(None, description="Publication date")
|
|
genre_id: str = Field(..., description="ID of the book genre")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"title": "The Great Gatsby",
|
|
"author": "F. Scott Fitzgerald",
|
|
"description": "A classic American novel about the Roaring Twenties.",
|
|
"page_count": 180,
|
|
"published_date": "1925-04-10T00:00:00",
|
|
"genre_id": "c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6"
|
|
}
|
|
}
|
|
|
|
class BookCreate(BookBase):
|
|
pass
|
|
|
|
class BookResponse(BookBase):
|
|
id: str
|
|
|
|
class Config:
|
|
orm_mode = True |