From f66dd247ac9e8b4303387eabbfc7c4aef09c24a1 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sat, 29 Mar 2025 22:53:43 +0100 Subject: [PATCH] Add Product schema --- schemas/product.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 schemas/product.py 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