27 lines
804 B
Python
27 lines
804 B
Python
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 |