Split AnswersIDs if not empty

This commit is contained in:
Andrea Fazzi 2019-12-18 09:57:07 +01:00
parent f0c937c438
commit 1e4ba14973

View file

@ -100,25 +100,28 @@ func (model *Response) Read(args map[string]string, w http.ResponseWriter, r *ht
return nil, err
}
srIDs := strings.Split(response.AnswersIDs, " ")
for _, srID := range srIDs {
id, err := strconv.Atoi(srID)
if err != nil {
return nil, err
}
response.SingleResponses = append(response.SingleResponses, &SingleResponse{uint(id)})
}
for _, sr := range response.SingleResponses {
var answer Answer
if err := DB().First(&answer, sr.AnswerID).Error; err != nil {
return nil, err
if response.AnswersIDs != "" {
srIDs := strings.Split(response.AnswersIDs, " ")
for _, srID := range srIDs {
id, err := strconv.Atoi(srID)
if err != nil {
return nil, err
}
response.SingleResponses = append(response.SingleResponses, &SingleResponse{uint(id)})
}
if answer.Correct {
response.Score++
for _, sr := range response.SingleResponses {
var answer Answer
if err := DB().First(&answer, sr.AnswerID).Error; err != nil {
return nil, err
}
if answer.Correct {
response.Score++
}
}
}
// Fetch questions in the given order