knowledge-api/api/dto/BaseErrorWord.go

54 lines
1.5 KiB
Go

package dto
import (
"fmt"
"knowledge/api/model"
)
// BaseErrorWordDto 基础数据-错别字
type BaseErrorWordDto struct {
WordId string `json:"word_id"` // 主键id
WordOld string `json:"word_old"` // 错别字
WordNew string `json:"word_new"` // 新字
QuestionIds string `json:"question_ids"` // 操作关联问题id
OperationTime *model.LocalTime `json:"operation_time"` // 操作时间
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetBaseErrorWordDto 详情
func GetBaseErrorWordDto(m *model.BaseErrorWord) *BaseErrorWordDto {
return &BaseErrorWordDto{
WordId: fmt.Sprintf("%d", m.WordId),
WordOld: m.WordOld,
WordNew: m.WordNew,
OperationTime: m.OperationTime,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// GetBaseErrorWordListDto 列表
func GetBaseErrorWordListDto(m []*model.BaseErrorWord) []*BaseErrorWordDto {
// 处理返回值
responses := make([]*BaseErrorWordDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &BaseErrorWordDto{
WordId: fmt.Sprintf("%d", v.WordId),
WordOld: v.WordOld,
WordNew: v.WordNew,
OperationTime: v.OperationTime,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}