拓展接口响应

This commit is contained in:
2025-11-21 16:37:09 +08:00
parent 534891309c
commit 4224be8567
5 changed files with 115 additions and 30 deletions

View File

@@ -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,
}
}