47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from uuid import UUID
|
|
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., min_length=1, max_length=200, description="Book title")
|
|
description: Optional[str] = Field(None, description="Book description")
|
|
isbn: str = Field(..., description="Book ISBN number")
|
|
author_id: str = Field(..., description="ID of the book's author")
|
|
publication_year: int = Field(..., ge=1000, le=2100, description="Year of publication")
|
|
pages: int = Field(..., gt=0, description="Number of pages")
|
|
genre: str = Field(..., description="Book genre")
|
|
publisher: str = Field(..., description="Book publisher")
|
|
|
|
class BookCreate(BookBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"title": "The Great Gatsby",
|
|
"description": "A novel by F. Scott Fitzgerald",
|
|
"isbn": "978-0743273565",
|
|
"author_id": "author_uuid",
|
|
"publication_year": 1925,
|
|
"pages": 180,
|
|
"genre": "Fiction",
|
|
"publisher": "Scribner"
|
|
}
|
|
}
|
|
|
|
class Book(BookBase):
|
|
id: UUID
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
"title": "The Great Gatsby",
|
|
"description": "A novel by F. Scott Fitzgerald",
|
|
"isbn": "978-0743273565",
|
|
"author_id": "author_uuid",
|
|
"publication_year": 1925,
|
|
"pages": 180,
|
|
"genre": "Fiction",
|
|
"publisher": "Scribner"
|
|
}
|
|
} |