diff --git a/packages/data/dbFuncs.go b/packages/data/dbFuncs.go index df89078..221b0dc 100644 --- a/packages/data/dbFuncs.go +++ b/packages/data/dbFuncs.go @@ -312,14 +312,10 @@ func (db *DB) GetGivenAnswers(bid, pid int64, sq []Question) ([]int, error) { ` for i, q := range sq { - var answer int - row := db.QueryRow(query, bid, pid, q.ID) - if err := row.Scan(&answer); err != nil { + if err := row.Scan(&answers[i]); err != nil { return nil, fmt.Errorf("error: *DB.GetGivenAnswers: row.Scan(): %v", err) } - - answers[i] = answer } return answers, nil diff --git a/packages/session/helperFuncs.go b/packages/session/helperFuncs.go index 76bbb28..ba937b4 100644 --- a/packages/session/helperFuncs.go +++ b/packages/session/helperFuncs.go @@ -56,28 +56,22 @@ func handleGivenAnswer(p *BriefingParticipant, i int64, r *http.Request) error { func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion { questions := make([]resultQuestion, len(sq)) for i, q := range sq { - question := resultQuestion{ - Text: q.Text, - Answers: make([]resultAnswer, len(q.Answers)), - } - - for j, a := range q.Answers { - answer := resultAnswer{Text: a.Text} + questions[i].Text = q.Text + questions[i].Answers = make([]resultAnswer, len(q.Answers)) + for j := range q.Answers { if j+1 == q.Correct { - answer.Correct = true + questions[i].Answers[j].Correct = true } else { - answer.Correct = false + questions[i].Answers[j].Correct = false } if j+1 == givenAnswers[i] { - answer.Chosen = true + questions[i].Answers[j].Chosen = true } else { - answer.Chosen = false + questions[i].Answers[j].Chosen = false } - question.Answers[j] = answer } - questions[i] = question } return questions