拓展接口响应

This commit is contained in:
2025-11-21 17:23:57 +08:00
parent 4224be8567
commit 7829ac9931
8 changed files with 142 additions and 49 deletions

View File

@@ -39,10 +39,11 @@ type NutrientResponse struct {
// ListNutrientRequest 定义了获取营养种类列表的请求参数
type ListNutrientRequest struct {
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
Name *string `json:"name" query:"name"` // 按名称模糊查询
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
Name *string `json:"name" query:"name"` // 按营养名称模糊查询
RawMaterialName *string `json:"raw_material_name" query:"raw_material_name"` // 按原料名称模糊查询
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
}
// ListNutrientResponse 是获取营养种类列表的响应结构
@@ -89,10 +90,11 @@ type RawMaterialResponse struct {
// ListRawMaterialRequest 定义了获取原料列表的请求参数
type ListRawMaterialRequest struct {
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
Name *string `json:"name" query:"name"` // 按名称模糊查询
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
Name *string `json:"name" query:"name"` // 按原料名称模糊查询
NutrientName *string `json:"nutrient_name" query:"nutrient_name"` // 按营养名称模糊查询
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
}
// ListRawMaterialResponse 是获取原料列表的响应结构

View File

@@ -143,7 +143,12 @@ func (s *feedManagementServiceImpl) GetNutrient(ctx context.Context, id uint32)
func (s *feedManagementServiceImpl) ListNutrients(ctx context.Context, req *dto.ListNutrientRequest) (*dto.ListNutrientResponse, error) {
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListNutrients")
nutrients, total, err := s.recipeSvc.ListNutrients(serviceCtx, req.Page, req.PageSize)
opts := repository.NutrientListOptions{
Name: req.Name,
RawMaterialName: req.RawMaterialName,
OrderBy: req.OrderBy,
}
nutrients, total, err := s.recipeSvc.ListNutrients(serviceCtx, opts, req.Page, req.PageSize)
if err != nil {
return nil, fmt.Errorf("获取营养种类列表失败: %w", err)
}
@@ -218,7 +223,12 @@ func (s *feedManagementServiceImpl) GetRawMaterial(ctx context.Context, id uint3
func (s *feedManagementServiceImpl) ListRawMaterials(ctx context.Context, req *dto.ListRawMaterialRequest) (*dto.ListRawMaterialResponse, error) {
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListRawMaterials")
rawMaterials, total, err := s.recipeSvc.ListRawMaterials(serviceCtx, req.Page, req.PageSize)
opts := repository.RawMaterialListOptions{
Name: req.Name,
NutrientName: req.NutrientName,
OrderBy: req.OrderBy,
}
rawMaterials, total, err := s.recipeSvc.ListRawMaterials(serviceCtx, opts, req.Page, req.PageSize)
if err != nil {
return nil, fmt.Errorf("获取原料列表失败: %w", err)
}