Add Book schema
This commit is contained in:
parent
00cbc6a44d
commit
1cf90d0f00
@ -2,14 +2,13 @@ from pydantic import BaseModel, Field
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
class BookBase(BaseModel):
|
class BookBase(BaseModel):
|
||||||
title: str = Field(..., description="Book title")
|
title: str = Field(..., min_length=1, description="Book title")
|
||||||
author: str = Field(..., description="Book author")
|
author: str = Field(..., min_length=1, 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")
|
description: Optional[str] = Field(None, description="Book description")
|
||||||
copies_available: int = Field(default=1, description="Number of copies available")
|
isbn: str = Field(..., description="Book ISBN number")
|
||||||
is_available: bool = Field(default=True, description="Book availability status")
|
price: int = Field(..., gt=0, description="Book price")
|
||||||
|
quantity: int = Field(0, ge=0, description="Available quantity")
|
||||||
|
is_available: bool = Field(True, description="Book availability status")
|
||||||
|
|
||||||
class BookCreate(BookBase):
|
class BookCreate(BookBase):
|
||||||
class Config:
|
class Config:
|
||||||
@ -17,11 +16,10 @@ class BookCreate(BookBase):
|
|||||||
"example": {
|
"example": {
|
||||||
"title": "The Great Gatsby",
|
"title": "The Great Gatsby",
|
||||||
"author": "F. Scott Fitzgerald",
|
"author": "F. Scott Fitzgerald",
|
||||||
|
"description": "A story of decadence and excess",
|
||||||
"isbn": "978-0743273565",
|
"isbn": "978-0743273565",
|
||||||
"publication_year": 1925,
|
"price": 999,
|
||||||
"publisher": "Charles Scribner's Sons",
|
"quantity": 50,
|
||||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
||||||
"copies_available": 5,
|
|
||||||
"is_available": True
|
"is_available": True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,11 +34,10 @@ class Book(BookBase):
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"title": "The Great Gatsby",
|
"title": "The Great Gatsby",
|
||||||
"author": "F. Scott Fitzgerald",
|
"author": "F. Scott Fitzgerald",
|
||||||
|
"description": "A story of decadence and excess",
|
||||||
"isbn": "978-0743273565",
|
"isbn": "978-0743273565",
|
||||||
"publication_year": 1925,
|
"price": 999,
|
||||||
"publisher": "Charles Scribner's Sons",
|
"quantity": 50,
|
||||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
|
||||||
"copies_available": 5,
|
|
||||||
"is_available": True
|
"is_available": True
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user