52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package dto
|
|
|
|
import (
|
|
"fmt"
|
|
"knowledge/api/model"
|
|
)
|
|
|
|
// QuestionOptionDto 题目选项表
|
|
type QuestionOptionDto struct {
|
|
OptionId string `json:"option_id"` // 主键id
|
|
QuestionId string `json:"question_id"` // 题目id
|
|
OptionValue string `json:"option_value"` // 选项内容
|
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
|
|
|
}
|
|
|
|
// GetQuestionOptionDto 题目选项详情
|
|
func GetQuestionOptionDto(m *model.QuestionOption) *QuestionOptionDto {
|
|
|
|
return &QuestionOptionDto{
|
|
OptionId: fmt.Sprintf("%d", m.OptionId),
|
|
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
|
OptionValue: m.OptionValue,
|
|
CreatedAt: m.CreatedAt,
|
|
UpdatedAt: m.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// GetQuestionOptionListDto 题目选项列表
|
|
func GetQuestionOptionListDto(m []*model.QuestionOption) []*QuestionOptionDto {
|
|
// 处理返回值
|
|
responses := make([]*QuestionOptionDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &QuestionOptionDto{
|
|
OptionId: fmt.Sprintf("%d", v.OptionId),
|
|
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
|
OptionValue: v.OptionValue,
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|