Merge branch 'fixsort' into 'main'
Fixsort See merge request backend/quiz/common!9
This commit is contained in:
commit
f853a933bb
@ -415,3 +415,32 @@ func (r *QuestionRepository) GetQuestionTitleByID(ctx context.Context, questionI
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (r *QuestionRepository) ForSortingResults(ctx context.Context, allAnswers []model.Answer) ([]model.Answer, error) {
|
||||
var questions []QueTitleResp
|
||||
|
||||
for _, answer := range allAnswers {
|
||||
questionData, err := r.GetQuestionTitleByID(ctx, answer.QuestionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
questionData.AnswerID = answer.Id
|
||||
questions = append(questions, questionData)
|
||||
|
||||
}
|
||||
sort.Slice(questions, func(i, j int) bool {
|
||||
return questions[i].Page < questions[j].Page
|
||||
})
|
||||
|
||||
// TODO O2 REFACTOR
|
||||
var sortedAllAnswers []model.Answer
|
||||
for _, que := range questions {
|
||||
for _, answer := range allAnswers {
|
||||
if que.AnswerID == answer.Id {
|
||||
sortedAllAnswers = append(sortedAllAnswers, answer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sortedAllAnswers, nil
|
||||
}
|
||||
|
@ -240,11 +240,11 @@ func (r *ResultRepository) GetResultAnswers(ctx context.Context, answerID uint64
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
New: row.New.Bool,
|
||||
Deleted: row.Deleted.Bool,
|
||||
Device: row.Device,
|
||||
DeviceType: row.DeviceType,
|
||||
OS: row.Os,
|
||||
IP: row.Ip,
|
||||
Browser: row.Browser,
|
||||
Device: row.Device,
|
||||
DeviceType: row.DeviceType,
|
||||
OS: row.Os,
|
||||
IP: row.Ip,
|
||||
Browser: row.Browser,
|
||||
}
|
||||
|
||||
answers = append(answers, answer)
|
||||
|
Loading…
Reference in New Issue
Block a user