Split AnswersIDs if not empty
This commit is contained in:
parent
f0c937c438
commit
1e4ba14973
1 changed files with 19 additions and 16 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue