Add Product schema
This commit is contained in:
parent
c4ffcbf20d
commit
f66dd247ac
29
schemas/product.py
Normal file
29
schemas/product.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from pydantic import BaseModel, Field, PositiveFloat, PositiveInt
|
||||||
|
|
||||||
|
# Base schema
|
||||||
|
class ProductBase(BaseModel):
|
||||||
|
name: str = Field(..., description="Product name")
|
||||||
|
description: str | None = Field(None, description="Product description")
|
||||||
|
price: PositiveFloat = Field(..., description="Product price")
|
||||||
|
stock_quantity: PositiveInt = Field(..., description="Product stock quantity")
|
||||||
|
|
||||||
|
# Create schema
|
||||||
|
class ProductCreate(ProductBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"name": "Product X",
|
||||||
|
"description": "This is a description of Product X",
|
||||||
|
"price": 9.99,
|
||||||
|
"stock_quantity": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Response schema
|
||||||
|
class Product(ProductBase):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user