48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., description="Book title")
|
|
author: str = Field(..., description="Book author")
|
|
isbn: str = Field(..., description="Book ISBN number")
|
|
published_year: Optional[int] = Field(None, description="Year of publication")
|
|
description: Optional[str] = Field(None, description="Book description")
|
|
price: int = Field(..., gt=0, description="Book price")
|
|
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": "978-0743273565",
|
|
"published_year": 1925,
|
|
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
"price": 999,
|
|
"is_available": True
|
|
}
|
|
}
|
|
|
|
class Book(BookBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"title": "The Great Gatsby",
|
|
"author": "F. Scott Fitzgerald",
|
|
"isbn": "978-0743273565",
|
|
"published_year": 1925,
|
|
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
"price": 999,
|
|
"is_available": True,
|
|
"created_at": "2023-01-01T00:00:00",
|
|
"updated_at": "2023-01-01T00:00:00"
|
|
}
|
|
} |