Files
zkxw/backend/app/schemas/category.py
T
2026-05-12 16:35:07 +08:00

62 lines
1.7 KiB
Python

"""商品分类Schema"""
from typing import Optional, List
from pydantic import BaseModel, Field
class CategoryBase(BaseModel):
"""分类基础Schema"""
name: str = Field(..., description="分类名称")
image_url: Optional[str] = Field(None, description="分类图片URL")
parent_id: Optional[str] = Field(None, description="父分类ID")
sort_order: int = Field(0, description="排序")
is_active: bool = Field(True, description="是否启用")
class CategoryCreate(CategoryBase):
"""创建分类"""
pass
class CategoryUpdate(BaseModel):
"""更新分类"""
name: Optional[str] = Field(None, description="分类名称")
image_url: Optional[str] = Field(None, description="分类图片URL")
parent_id: Optional[str] = Field(None, description="父分类ID")
sort_order: Optional[int] = Field(None, description="排序")
is_active: Optional[bool] = Field(None, description="是否启用")
class CategoryTreeNode(BaseModel):
"""分类树节点"""
id: str
name: str
parentId: Optional[str] = None
sortOrder: int = 0
isActive: bool = True
children: List["CategoryTreeNode"] = []
class Config:
from_attributes = True
class CategoryResponse(CategoryBase):
"""分类响应"""
id: str
create_at: Optional[str] = None
create_by: Optional[str] = None
create_name: Optional[str] = None
update_at: Optional[str] = None
update_by: Optional[str] = None
class Config:
from_attributes = True
class CategoryListResponse(BaseModel):
"""分类列表响应"""
items: List[CategoryResponse]
total: int
page: int
pageSize: int
totalPages: int