拓展接口响应
This commit is contained in:
@@ -9,12 +9,24 @@ func ConvertNutrientToDTO(nutrient *models.Nutrient) *NutrientResponse {
|
||||
if nutrient == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
rawMaterials := make([]NutrientRawMaterialDTO, 0, len(nutrient.RawMaterialNutrients))
|
||||
for _, rmn := range nutrient.RawMaterialNutrients {
|
||||
// 根据您的反馈,移除了不必要的 nil 检查,以保持代码简洁和一致性
|
||||
rawMaterials = append(rawMaterials, NutrientRawMaterialDTO{
|
||||
ID: rmn.RawMaterial.ID,
|
||||
Name: rmn.RawMaterial.Name,
|
||||
Value: rmn.Value,
|
||||
})
|
||||
}
|
||||
|
||||
return &NutrientResponse{
|
||||
ID: nutrient.ID,
|
||||
CreatedAt: nutrient.CreatedAt,
|
||||
UpdatedAt: nutrient.UpdatedAt,
|
||||
Name: nutrient.Name,
|
||||
Description: nutrient.Description,
|
||||
ID: nutrient.ID,
|
||||
CreatedAt: nutrient.CreatedAt,
|
||||
UpdatedAt: nutrient.UpdatedAt,
|
||||
Name: nutrient.Name,
|
||||
Description: nutrient.Description,
|
||||
RawMaterials: rawMaterials,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user