From d71d20b9f333fa41e1f08081dbd2284e1baaf0fd Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 30 Mar 2025 08:33:47 +0100 Subject: [PATCH] Add Product schema --- schemas/product.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 schemas/product.py diff --git a/schemas/product.py b/schemas/product.py new file mode 100644 index 0000000..1947c81 --- /dev/null +++ b/schemas/product.py @@ -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 \ No newline at end of file