From 73d735e2074f7b73784011e0f4d4fe1d38d6b7b2 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 10:47:38 +0000 Subject: [PATCH] Add Book schema --- schemas/book.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 schemas/book.py diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..fff13f6 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,40 @@ +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") + description: Optional[str] = Field(None, max_length=1000, description="Book description") + isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN number") + +class BookCreate(BookBase): + class Config: + schema_extra = { + "example": { + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "description": "A novel about the American Dream", + "isbn": "9780743273565" + } + } + +class Book(BookBase): + id: UUID + 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", + "description": "A novel about the American Dream", + "isbn": "9780743273565", + "created_at": "2023-01-01T00:00:00", + "updated_at": "2023-01-01T00:00:00" + } + } \ No newline at end of file