From 5ec12f2cbb5c2d8aed731b075fe3606793a97a84 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 23:22:44 +0000 Subject: [PATCH] Add Book schema --- schemas/book.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 schemas/book.py diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..722ec36 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,60 @@ +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") + publication_year: Optional[int] = Field(None, ge=1000, le=2100, description="Year of publication") + publisher: Optional[str] = Field(None, max_length=100, description="Book publisher") + description: Optional[str] = Field(None, max_length=1000, description="Book description") + genre: Optional[str] = Field(None, max_length=50, description="Book genre") + pages: Optional[int] = Field(None, gt=0, description="Number of pages") + language: Optional[str] = Field(None, max_length=50, description="Book language") + price: Optional[int] = Field(None, ge=0, description="Book price") + +class BookCreate(BookBase): + class Config: + schema_extra = { + "example": { + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "isbn": "9780743273565", + "publication_year": 1925, + "publisher": "Scribner", + "description": "A story of the fabulously wealthy Jay Gatsby", + "genre": "Fiction", + "pages": 180, + "language": "English", + "price": 1499 + } + } + +class Book(BookBase): + id: UUID + is_available: bool = True + created_at: datetime + updated_at: datetime + + class Config: + orm_mode = True + schema_extra = { + "example": { + "id": "123e4567-e89b-12d3-a456-426614174000", + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "isbn": "9780743273565", + "publication_year": 1925, + "publisher": "Scribner", + "description": "A story of the fabulously wealthy Jay Gatsby", + "genre": "Fiction", + "pages": 180, + "language": "English", + "is_available": True, + "price": 1499, + "created_at": "2023-01-01T00:00:00", + "updated_at": "2023-01-01T00:00:00" + } + } \ No newline at end of file