Add Product schema
This commit is contained in:
parent
c56592a218
commit
d71d20b9f3
27
schemas/product.py
Normal file
27
schemas/product.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from pydantic import BaseModel, Field, constr
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class ProductBase(BaseModel):
|
||||||
|
name: constr(min_length=1) = Field(..., description="Product name")
|
||||||
|
description: Optional[str] = Field(None, description="Product description")
|
||||||
|
price: float = Field(..., gt=0, description="Product price")
|
||||||
|
stock_quantity: int = Field(..., ge=0, description="Product stock quantity")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"name": "Product Name",
|
||||||
|
"description": "This is a product description",
|
||||||
|
"price": 9.99,
|
||||||
|
"stock_quantity": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProductCreate(ProductBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ProductResponse(ProductBase):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user