Browse Source

fix:培训考试试卷详情问题列表添加答案字段

liuyaqi 3 năm trước cách đây
mục cha
commit
67befe5c47
2 tập tin đã thay đổi với 8 bổ sung0 xóa
  1. 1 0
      model/learning/learning_question.go
  2. 7 0
      service/learning/question.go

+ 1 - 0
model/learning/learning_question.go

@@ -26,6 +26,7 @@ type LearningQuestionOption struct {
 
 type LearningQuestionGetRsp struct {
 	LearningQuestion
+	Answer  string      `json:"answer,omitempty"`
 	Content interface{} `json:"content"`
 }
 

+ 7 - 0
service/learning/question.go

@@ -106,8 +106,15 @@ func (s LearningQuestionService) List(ctx context.Context, req *learning.Learnin
 		if err != nil {
 			return 0, nil, err
 		}
+		answer := []string{}
+		for _, item := range content {
+			if item.IsCorrect {
+				answer = append(answer, item.Name)
+			}
+		}
 		questions = append(questions, &learning.LearningQuestionGetRsp{
 			LearningQuestion: *q,
+			Answer:           strings.Join(answer, " "),
 			Content:          content,
 		})
 	}