feat 答题记录
This commit is contained in:
@@ -33,12 +33,14 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) {
|
||||
}
|
||||
|
||||
type RecordItem struct {
|
||||
QuestionSn string `gorm:"column:question_sn"`
|
||||
Question string `gorm:"column:question"`
|
||||
Difficulty int32 `gorm:"column:difficulty"`
|
||||
Category string `gorm:"column:category"`
|
||||
IsCorrect int32 `gorm:"column:is_correct"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
QuestionSn string `gorm:"column:question_sn"`
|
||||
Question string `gorm:"column:question"`
|
||||
Difficulty int32 `gorm:"column:difficulty"`
|
||||
Category string `gorm:"column:category"`
|
||||
IsCorrect int32 `gorm:"column:is_correct"`
|
||||
QuestionAnswer string `gorm:"column:question_answer"`
|
||||
Answer string `gorm:"column:answer"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, int64, error) {
|
||||
@@ -48,8 +50,9 @@ func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, in
|
||||
d.query.Question.Sn.As("question_sn"),
|
||||
d.query.Question.Question,
|
||||
d.query.Question.Difficulty,
|
||||
d.query.Question.Answer.As("question_answer"),
|
||||
d.query.Category.Category,
|
||||
d.query.Record.IsCorrect,
|
||||
d.query.Record.Answer,
|
||||
d.query.Record.CreatedAt,
|
||||
).
|
||||
Where(d.query.Record.UserSn.Eq(usn)).
|
||||
|
||||
@@ -146,6 +146,28 @@ func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetQuestionInfo 获取具体的题目
|
||||
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.QuestionSn)
|
||||
if err != nil {
|
||||
log.Errorf("GetQuestionInfo error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
log.Errorf("GetQuestionInfo json.Unmarshal error: %v, data: %v", err, question.Options)
|
||||
return nil, err
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.GetQuestionInfoResp{
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AnswerQuestion 回答题目
|
||||
func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn)
|
||||
@@ -209,12 +231,13 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp
|
||||
resp := make([]*grpc_pb.GetRecordItem, 0)
|
||||
for _, record := range records {
|
||||
resp = append(resp, &grpc_pb.GetRecordItem{
|
||||
QuestionSn: record.QuestionSn,
|
||||
Question: record.Question,
|
||||
Difficulty: record.Difficulty,
|
||||
Category: record.Category,
|
||||
IsCorrect: record.IsCorrect,
|
||||
CreateTime: record.CreatedAt.Unix(),
|
||||
QuestionSn: record.QuestionSn,
|
||||
Question: record.Question,
|
||||
Difficulty: record.Difficulty,
|
||||
Category: record.Category,
|
||||
QuestionAnswer: record.QuestionAnswer,
|
||||
Answer: record.Answer,
|
||||
CreateTime: record.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetRecordResp{
|
||||
|
||||
Reference in New Issue
Block a user