Add Product schema

This commit is contained in:
Backend IM Bot 2025-03-30 08:33:47 +01:00
parent c56592a218
commit d71d20b9f3

27
schemas/product.py Normal file
View File

@ -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