Add Book schema
This commit is contained in:
parent
c4af320dc6
commit
e49a34e295
38
schemas/book.py
Normal file
38
schemas/book.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user