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