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