From 621db147176cc8c704079baa45bfa0e184f79641 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 14:12:18 +0000 Subject: [PATCH] Add Product schema --- schemas/product.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 schemas/product.py diff --git a/schemas/product.py b/schemas/product.py new file mode 100644 index 0000000..f5f8cee --- /dev/null +++ b/schemas/product.py @@ -0,0 +1,40 @@ +from pydantic import BaseModel, Field +from typing import Optional + +class ProductBase(BaseModel): + name: str = Field(..., min_length=1, description="Product name") + description: Optional[str] = Field(None, description="Product description") + price: float = Field(..., gt=0, description="Product price") + stock: int = Field(default=0, ge=0, description="Product stock quantity") + sku: str = Field(..., min_length=1, description="Product SKU") + is_active: bool = Field(default=True, description="Product status") + +class ProductCreate(ProductBase): + class Config: + schema_extra = { + "example": { + "name": "Sample Product", + "description": "A detailed product description", + "price": 29.99, + "stock": 100, + "sku": "PROD-001", + "is_active": True + } + } + +class Product(ProductBase): + id: int = Field(..., description="Product ID") + + class Config: + orm_mode = True + schema_extra = { + "example": { + "id": 1, + "name": "Sample Product", + "description": "A detailed product description", + "price": 29.99, + "stock": 100, + "sku": "PROD-001", + "is_active": True + } + } \ No newline at end of file