From fa41f9d5654bcfc83a9c260c1154f9f10967441f Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 22:56:11 +0100 Subject: [PATCH] Add Book schema --- schemas/book.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 schemas/book.py diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..8b1a363 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,29 @@ +from pydantic import BaseModel, Field +from datetime import datetime + +class BookBase(BaseModel): + title: str = Field(..., description="Book title") + author: str = Field(..., description="Book author", index=True) + description: str | None = Field(None, description="Book description") + page_count: int = Field(..., gt=0, description="Number of pages") + published_date: datetime = Field(..., description="Publication date") + isbn: str = Field(..., description="ISBN number", index=True) + + class Config: + orm_mode = True + +class BookCreate(BookBase): + pass + +class BookResponse(BookBase): + class Config: + schema_extra = { + "example": { + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "description": "A novel about the decadence of the Jazz Age.", + "page_count": 180, + "published_date": "1925-04-10T00:00:00", + "isbn": "978-0743273565" + } + } \ No newline at end of file