2024-06-19 14:30:11 +08:00

53 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dto
import (
"fmt"
"knowledge/api/model"
)
// LabelDto 标签表
type LabelDto struct {
LabelId string `json:"label_id"` // 主键id
LabelName string `json:"label_name"` // 标签名称
ParentId string `json:"parent_id"` // 父级ID0表示一级
LabelLevel int `json:"label_level"` // 级别1:1级 2:2级 3:3级
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
}
// GetLabelDto 标签详情
func GetLabelDto(m *model.Label) *LabelDto {
return &LabelDto{
LabelId: fmt.Sprintf("%d", m.LabelId),
LabelName: m.LabelName,
ParentId: fmt.Sprintf("%d", m.ParentId),
LabelLevel: m.LabelLevel,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// GetLabelListDto 标签列表
func GetLabelListDto(m []*model.Label) []*LabelDto {
// 处理返回值
responses := make([]*LabelDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &LabelDto{
LabelId: fmt.Sprintf("%d", v.LabelId),
LabelName: v.LabelName,
ParentId: fmt.Sprintf("%d", v.ParentId),
LabelLevel: v.LabelLevel,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}