52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., min_length=1, max_length=200, description="Book title")
|
|
author: str = Field(..., min_length=1, max_length=100, description="Book author")
|
|
isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN")
|
|
description: Optional[str] = Field(None, description="Book description")
|
|
publication_year: Optional[int] = Field(None, ge=1000, le=2100, description="Year of publication")
|
|
pages: Optional[int] = Field(None, gt=0, description="Number of pages")
|
|
publisher: Optional[str] = Field(None, max_length=100, description="Book publisher")
|
|
is_available: bool = Field(default=True, description="Book availability status")
|
|
|
|
class BookCreate(BookBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"title": "The Great Gatsby",
|
|
"author": "F. Scott Fitzgerald",
|
|
"isbn": "9780743273565",
|
|
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
"publication_year": 1925,
|
|
"pages": 180,
|
|
"publisher": "Scribner",
|
|
"is_available": True
|
|
}
|
|
}
|
|
|
|
class Book(BookBase):
|
|
id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
"title": "The Great Gatsby",
|
|
"author": "F. Scott Fitzgerald",
|
|
"isbn": "9780743273565",
|
|
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
"publication_year": 1925,
|
|
"pages": 180,
|
|
"publisher": "Scribner",
|
|
"is_available": True,
|
|
"created_at": "2023-01-01T00:00:00",
|
|
"updated_at": "2023-01-01T00:00:00"
|
|
}
|
|
} |