feat 答题记录

This commit is contained in:
2026-01-14 21:05:40 +08:00
parent b16bd8960a
commit e482833f72
4 changed files with 42 additions and 16 deletions

View File

@@ -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{