healthapp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.1 KiB

package logic
import (
"context"
"encoding/json"
"healthapi/internal/model"
"healthapi/internal/svc"
"healthapi/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetQuestionsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetQuestionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetQuestionsLogic {
return &GetQuestionsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetQuestionsLogic) GetQuestions() (resp *types.QuestionsResp, err error) {
var questions []model.QuestionBank
l.svcCtx.DB.Order("constitution_type, order_num").Find(&questions)
resp = &types.QuestionsResp{
Questions: make([]types.Question, 0, len(questions)),
}
for _, q := range questions {
var options []string
json.Unmarshal([]byte(q.Options), &options)
resp.Questions = append(resp.Questions, types.Question{
ID: int(q.ID),
ConstitutionType: q.ConstitutionType,
QuestionText: q.QuestionText,
Options: options,
OrderNum: q.OrderNum,
})
}
return resp, nil
}