From e49a34e29582c05f2912ae74450a2872785495c1 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 01:27:18 +0000 Subject: [PATCH] Add Book schema --- schemas/book.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 schemas/book.py diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..0fb5f05 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,38 @@ +from pydantic import BaseModel, Field +from typing import Optional +from datetime import datetime + +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") + description: Optional[str] = Field(None, description="Book description") + isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN") + publication_year: int = Field(..., ge=1000, le=2100, description="Year of publication") + publisher: str = Field(..., min_length=1, max_length=100, description="Book publisher") + cover_image: Optional[str] = Field(None, description="URL to book cover image") + price: int = Field(..., ge=0, description="Book price in cents") + 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", + "description": "A story of the fabulously wealthy Jay Gatsby", + "isbn": "9780743273565", + "publication_year": 1925, + "publisher": "Scribner", + "cover_image": "https://example.com/gatsby.jpg", + "price": 1499, + "is_available": True + } + } + +class Book(BookBase): + id: int + created_at: datetime + updated_at: datetime + + class Config: + orm_mode = True \ No newline at end of file