拓展接口响应

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

View File

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

View File

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

View File

@@ -9,12 +9,24 @@ func ConvertNutrientToDTO(nutrient *models.Nutrient) *NutrientResponse {
if nutrient == nil { if nutrient == nil {
return 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{ return &NutrientResponse{
ID: nutrient.ID, ID: nutrient.ID,
CreatedAt: nutrient.CreatedAt, CreatedAt: nutrient.CreatedAt,
UpdatedAt: nutrient.UpdatedAt, UpdatedAt: nutrient.UpdatedAt,
Name: nutrient.Name, Name: nutrient.Name,
Description: nutrient.Description, Description: nutrient.Description,
RawMaterials: rawMaterials,
} }
} }

View File

@@ -20,13 +20,21 @@ type UpdateNutrientRequest struct {
Description string `json:"description" validate:"max=255"` // 描述 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 营养种类响应体 // NutrientResponse 营养种类响应体
type NutrientResponse struct { type NutrientResponse struct {
ID uint32 `json:"id"` ID uint32 `json:"id"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
RawMaterials []NutrientRawMaterialDTO `json:"raw_materials"` // 包含此营养的原料列表
} }
// ListNutrientRequest 定义了获取营养种类列表的请求参数 // ListNutrientRequest 定义了获取营养种类列表的请求参数