dingdanquanliucheng/backend/app/schemas/products.py
taiyi 9b32afdbb4 为后端全部 86 个 Python 文件添加中文注释
覆盖所有模块:
- api 层:17 个路由文件,每个接口标注用途、参数、返回值、权限
- services 层:18 个服务文件,每个方法标注作用、参数、返回值、调用方
- repositories 层:13 个仓储文件,每个方法标注查询逻辑和被调用方
- schemas 层:11 个请求/响应体文件,每个字段标注业务含义
- core 层:config、security、exceptions、responses、error_codes
- models 层:19 个 ORM 模型类,每个表标注业务含义和关联关系
- scripts:bootstrap_data、smoke_check
- migrations:env.py 和版本迁移文件

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 07:23:33 +08:00

157 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
产品模块请求模型
定义产品及产品分类管理相关的请求体数据模型,供 products 路由使用。
包含产品分类的创建/更新、产品的创建/更新,以及产品规格的更新操作。
"""
from pydantic import BaseModel, Field
class CreateCategoryRequest(BaseModel):
"""创建产品分类请求体。被 POST /api/products/categories 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号,数值越小越靠前"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
class UpdateCategoryRequest(BaseModel):
"""更新产品分类请求体。被 PUT /api/products/categories/{id} 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
class ProductSpecificationPayload(BaseModel):
"""产品规格载荷,用于创建产品时携带规格信息。"""
specification: str
"""规格名称(如尺寸、型号等)"""
unit: str
"""计量单位(如个、箱、米等)"""
category_id: int | None = None
"""关联分类 ID"""
cost_price: float = 0
"""成本价"""
sale_price: float = 0
"""销售价"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
is_default: bool = False
"""是否为默认规格"""
class CreateProductRequest(BaseModel):
"""创建产品请求体。被 POST /api/products 路由使用。"""
product_name: str
"""产品名称"""
category_id: int | None = None
"""所属分类 ID"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
specifications: list[ProductSpecificationPayload] = Field(default_factory=list)
"""产品规格列表,支持创建时同时创建多个规格"""
class UpdateProductRequest(BaseModel):
"""更新产品基本信息请求体。被 PUT /api/products/{id} 路由使用。"""
product_name: str
"""产品名称"""
category_id: int | None = None
"""所属分类 ID"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
class UpdateProductSpecificationRequest(BaseModel):
"""更新产品规格请求体。被 PUT /api/products/specifications/{id} 路由使用。"""
specification: str
"""规格名称"""
unit: str
"""计量单位"""
category_id: int | None = None
"""关联分类 ID"""
cost_price: float = 0
"""成本价"""
sale_price: float = 0
"""销售价"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
is_default: bool = False
"""是否为默认规格"""
class UpdateProductCategoryRequest(BaseModel):
"""更新产品分类请求体。被 PUT /api/products/categories/{id} 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""