53 lines
962 B
Python
53 lines
962 B
Python
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class CategoryBase(BaseModel):
|
|
"""Base schema for category data."""
|
|
|
|
name: str
|
|
description: Optional[str] = None
|
|
|
|
|
|
class CategoryCreate(CategoryBase):
|
|
"""Schema for creating a new category."""
|
|
|
|
pass
|
|
|
|
|
|
class CategoryUpdate(BaseModel):
|
|
"""Schema for updating a category."""
|
|
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
|
|
|
|
class ProductInCategory(BaseModel):
|
|
"""Schema for product data in category responses."""
|
|
|
|
id: int
|
|
name: str
|
|
price: float
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class CategoryResponse(CategoryBase):
|
|
"""Schema for category responses."""
|
|
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class CategoryWithProducts(CategoryResponse):
|
|
"""Schema for category with related products."""
|
|
|
|
products: List[ProductInCategory] = []
|
|
|
|
class Config:
|
|
from_attributes = True
|