diff --git a/schemas/book.py b/schemas/book.py new file mode 100644 index 0000000..f07cd4f --- /dev/null +++ b/schemas/book.py @@ -0,0 +1,46 @@ +from pydantic import BaseModel, Field +from typing import Optional + +class BookBase(BaseModel): + title: str = Field(..., description="Book title") + author: str = Field(..., description="Book author") + isbn: str = Field(..., description="Book ISBN number") + publication_year: Optional[int] = Field(None, description="Year of publication") + publisher: Optional[str] = Field(None, description="Book publisher") + description: Optional[str] = Field(None, description="Book description") + copies_available: int = Field(default=1, description="Number of copies available") + 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", + "isbn": "978-0743273565", + "publication_year": 1925, + "publisher": "Charles Scribner's Sons", + "description": "A story of the fabulously wealthy Jay Gatsby", + "copies_available": 5, + "is_available": True + } + } + +class Book(BookBase): + id: int = Field(..., description="Book ID") + + class Config: + orm_mode = True + schema_extra = { + "example": { + "id": 1, + "title": "The Great Gatsby", + "author": "F. Scott Fitzgerald", + "isbn": "978-0743273565", + "publication_year": 1925, + "publisher": "Charles Scribner's Sons", + "description": "A story of the fabulously wealthy Jay Gatsby", + "copies_available": 5, + "is_available": True + } + } \ No newline at end of file