diff --git a/schemas/product.py b/schemas/product.py new file mode 100644 index 0000000..d5d13df --- /dev/null +++ b/schemas/product.py @@ -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 \ No newline at end of file