Add Book schema

This commit is contained in:
Backend IM Bot 2025-03-26 16:14:48 +00:00
parent 719919cb77
commit 041796cc84

48
schemas/book.py Normal file
View File

@ -0,0 +1,48 @@
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
class BookBase(BaseModel):
title: str = Field(..., description="Book title")
author: str = Field(..., description="Book author")
isbn: str = Field(..., description="Book ISBN number")
published_year: Optional[int] = Field(None, description="Year of publication")
description: Optional[str] = Field(None, description="Book description")
price: int = Field(..., gt=0, description="Book price")
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",
"published_year": 1925,
"description": "A story of the fabulously wealthy Jay Gatsby",
"price": 999,
"is_available": True
}
}
class Book(BookBase):
id: int
created_at: datetime
updated_at: datetime
class Config:
orm_mode = True
schema_extra = {
"example": {
"id": 1,
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"isbn": "978-0743273565",
"published_year": 1925,
"description": "A story of the fabulously wealthy Jay Gatsby",
"price": 999,
"is_available": True,
"created_at": "2023-01-01T00:00:00",
"updated_at": "2023-01-01T00:00:00"
}
}