From 013efd1dd62e25610d3355c926fa80c1a850b7db Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 17:27:01 +0100 Subject: [PATCH] Add Book schema --- schemas/book.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 schemas/book.py diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..4687041 --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,51 @@ +from pydantic import BaseModel, Field + +# Base Schema +class BookBase(BaseModel): + title: str = Field(..., description="Book title") + author: str = Field(..., description="Book author") + description: str = Field(None, description="Book description") + published_year: int = Field(None, description="Year the book was published") + + class Config: + schema_extra = { + "example": { + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "description": "A novel about the decadence of the Jazz Age.", + "published_year": 1925 + } + } + +# Create Schema +class BookCreate(BookBase): + isbn: str = Field(..., description="Book ISBN number") + + class Config: + schema_extra = { + "example": { + "title": "To Kill a Mockingbird", + "author": "Harper Lee", + "description": "A classic novel about racial injustice.", + "published_year": 1960, + "isbn": "978-0060935467" + } + } + +# Response Schema +class Book(BookBase): + id: int = Field(..., description="Book ID") + isbn: str = Field(..., description="Book ISBN number") + + class Config: + orm_mode = True + schema_extra = { + "example": { + "id": 1, + "title": "1984", + "author": "George Orwell", + "description": "A dystopian novel about totalitarianism.", + "published_year": 1949, + "isbn": "978-0451524935" + } + } \ No newline at end of file