feat 答题记录
This commit is contained in:
@@ -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