Add Book schema
This commit is contained in:
parent
1efa0731ce
commit
efa22ff546
32
schemas/book.py
Normal file
32
schemas/book.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class BookBase(BaseModel):
|
||||||
|
title: str = Field(..., description="Book title")
|
||||||
|
author: str = Field(..., description="Book author")
|
||||||
|
description: Optional[str] = Field(None, description="Book description")
|
||||||
|
page_count: Optional[int] = Field(None, description="Number of pages")
|
||||||
|
published_date: Optional[datetime] = Field(None, description="Publication date")
|
||||||
|
genre_id: str = Field(..., description="ID of the book genre")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"title": "The Great Gatsby",
|
||||||
|
"author": "F. Scott Fitzgerald",
|
||||||
|
"description": "A classic American novel about the Roaring Twenties.",
|
||||||
|
"page_count": 180,
|
||||||
|
"published_date": "1925-04-10T00:00:00",
|
||||||
|
"genre_id": "c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BookCreate(BookBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BookResponse(BookBase):
|
||||||
|
id: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user