diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..23abe29 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,48 @@ +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" + } + } \ No newline at end of file