product_parameter_value.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """Pydantic schemas - 商品参数值"""
  2. from pydantic import BaseModel, Field, ConfigDict
  3. from typing import Optional, List
  4. from datetime import datetime
  5. class ProductParameterValueBase(BaseModel):
  6. """商品参数值基础字段"""
  7. model_config = ConfigDict(populate_by_name=True)
  8. product_id: str = Field(..., description="商品ID", alias="productId")
  9. parameter_id: str = Field(..., description="参数ID", alias="parameterId")
  10. param_value: Optional[str] = Field(None, description="参数值", alias="paramValue")
  11. class ProductParameterValueCreate(ProductParameterValueBase):
  12. """创建商品参数值请求"""
  13. pass
  14. class ProductParameterValueUpdate(BaseModel):
  15. """更新商品参数值请求"""
  16. model_config = ConfigDict(populate_by_name=True)
  17. param_value: Optional[str] = Field(None, description="参数值", alias="paramValue")
  18. class ProductParameterValueBatchSave(BaseModel):
  19. """批量保存商品参数值请求"""
  20. model_config = ConfigDict(populate_by_name=True)
  21. product_id: str = Field(..., description="商品ID", alias="productId")
  22. values: List[ProductParameterValueCreate] = Field(..., description="参数值列表")
  23. class ProductParameterValueResponse(BaseModel):
  24. """商品参数值响应"""
  25. id: str
  26. product_id: str
  27. parameter_id: str
  28. parameter_name: Optional[str] = None
  29. parameter_code: Optional[str] = None
  30. param_type: Optional[str] = None
  31. param_value: Optional[str] = None
  32. sort_order: int
  33. create_at: datetime
  34. create_by: Optional[str] = None
  35. create_name: Optional[str] = None
  36. update_at: Optional[datetime] = None
  37. class Config:
  38. from_attributes = True
  39. class ProductParameterValueListResponse(BaseModel):
  40. """商品参数值列表响应"""
  41. list: List[ProductParameterValueResponse]
  42. total: int
  43. class ProductParameterValueWithParameterResponse(BaseModel):
  44. """带参数信息的商品参数值响应"""
  45. id: str
  46. product_id: str
  47. parameter_id: str
  48. parameter_name: str
  49. parameter_code: str
  50. param_type: str
  51. options: Optional[str] = None
  52. placeholder: Optional[str] = None
  53. param_value: Optional[str] = None
  54. sort_order: int
  55. class Config:
  56. from_attributes = True