拓展接口响应

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

@@ -3074,6 +3074,7 @@ const docTemplate = `{
},
{
"enum": [
7,
-1,
0,
1,
@@ -3083,12 +3084,12 @@ const docTemplate = `{
5,
-1,
5,
6,
7
6
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -3098,8 +3099,7 @@ const docTemplate = `{
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
],
"name": "level",
"in": "query"
@@ -7336,6 +7336,23 @@ const docTemplate = `{
}
}
},
"dto.NutrientRawMaterialDTO": {
"type": "object",
"properties": {
"id": {
"description": "原料ID",
"type": "integer"
},
"name": {
"description": "原料名称",
"type": "string"
},
"value": {
"description": "该原料中此营养素的含量",
"type": "number"
}
}
},
"dto.NutrientResponse": {
"type": "object",
"properties": {
@@ -7351,6 +7368,13 @@ const docTemplate = `{
"name": {
"type": "string"
},
"raw_materials": {
"description": "包含此营养的原料列表",
"type": "array",
"items": {
"$ref": "#/definitions/dto.NutrientRawMaterialDTO"
}
},
"updated_at": {
"type": "string"
}
@@ -9622,6 +9646,7 @@ const docTemplate = `{
"type": "integer",
"format": "int32",
"enum": [
7,
-1,
0,
1,
@@ -9631,10 +9656,10 @@ const docTemplate = `{
5,
-1,
5,
6,
7
6
],
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -9644,8 +9669,7 @@ const docTemplate = `{
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
]
}
},

View File

@@ -3066,6 +3066,7 @@
},
{
"enum": [
7,
-1,
0,
1,
@@ -3075,12 +3076,12 @@
5,
-1,
5,
6,
7
6
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -3090,8 +3091,7 @@
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
],
"name": "level",
"in": "query"
@@ -7328,6 +7328,23 @@
}
}
},
"dto.NutrientRawMaterialDTO": {
"type": "object",
"properties": {
"id": {
"description": "原料ID",
"type": "integer"
},
"name": {
"description": "原料名称",
"type": "string"
},
"value": {
"description": "该原料中此营养素的含量",
"type": "number"
}
}
},
"dto.NutrientResponse": {
"type": "object",
"properties": {
@@ -7343,6 +7360,13 @@
"name": {
"type": "string"
},
"raw_materials": {
"description": "包含此营养的原料列表",
"type": "array",
"items": {
"$ref": "#/definitions/dto.NutrientRawMaterialDTO"
}
},
"updated_at": {
"type": "string"
}
@@ -9614,6 +9638,7 @@
"type": "integer",
"format": "int32",
"enum": [
7,
-1,
0,
1,
@@ -9623,10 +9648,10 @@
5,
-1,
5,
6,
7
6
],
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -9636,8 +9661,7 @@
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
]
}
},

View File

@@ -884,6 +884,18 @@ definitions:
user_id:
type: integer
type: object
dto.NutrientRawMaterialDTO:
properties:
id:
description: 原料ID
type: integer
name:
description: 原料名称
type: string
value:
description: 该原料中此营养素的含量
type: number
type: object
dto.NutrientResponse:
properties:
created_at:
@@ -894,6 +906,11 @@ definitions:
type: integer
name:
type: string
raw_materials:
description: 包含此营养的原料列表
items:
$ref: '#/definitions/dto.NutrientRawMaterialDTO'
type: array
updated_at:
type: string
type: object
@@ -2500,6 +2517,7 @@ definitions:
- PlanTypeFilterSystem
zapcore.Level:
enum:
- 7
- -1
- 0
- 1
@@ -2510,10 +2528,10 @@ definitions:
- -1
- 5
- 6
- 7
format: int32
type: integer
x-enum-varnames:
- _numLevels
- DebugLevel
- InfoLevel
- WarnLevel
@@ -2524,7 +2542,6 @@ definitions:
- _minLevel
- _maxLevel
- InvalidLevel
- _numLevels
info:
contact:
email: divano@example.com
@@ -4373,6 +4390,7 @@ paths:
name: end_time
type: string
- enum:
- 7
- -1
- 0
- 1
@@ -4383,12 +4401,12 @@ paths:
- -1
- 5
- 6
- 7
format: int32
in: query
name: level
type: integer
x-enum-varnames:
- _numLevels
- DebugLevel
- InfoLevel
- WarnLevel
@@ -4399,7 +4417,6 @@ paths:
- _minLevel
- _maxLevel
- InvalidLevel
- _numLevels
- enum:
- 邮件
- 企业微信

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

View File

@@ -20,13 +20,21 @@ type UpdateNutrientRequest struct {
Description string `json:"description" validate:"max=255"` // 描述
}
// NutrientRawMaterialDTO 用于在营养素信息中展示关联的原料及其含量
type NutrientRawMaterialDTO struct {
ID uint32 `json:"id"` // 原料ID
Name string `json:"name"` // 原料名称
Value float32 `json:"value"` // 该原料中此营养素的含量
}
// NutrientResponse 营养种类响应体
type NutrientResponse struct {
ID uint32 `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
Description string `json:"description"`
ID uint32 `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
Description string `json:"description"`
RawMaterials []NutrientRawMaterialDTO `json:"raw_materials"` // 包含此营养的原料列表
}
// ListNutrientRequest 定义了获取营养种类列表的请求参数