From 817029c0dc05ab718b77de305462c732ec8b7a74 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 1 Nov 2023 11:43:06 +0100 Subject: [PATCH] =?UTF-8?q?=C3=9Cberfl=C3=BCssige=20Variableninstanziierun?= =?UTF-8?q?gen=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data/dbFuncs.go | 6 +----- packages/session/helperFuncs.go | 20 +++++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) 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