Add Product schema

This commit is contained in:
Backend IM Bot 2025-03-29 22:53:43 +01:00
parent c4ffcbf20d
commit f66dd247ac

29
schemas/product.py Normal file
View File

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