Überflüssige Variableninstanziierungen entfernt
This commit is contained in:
parent
6ca11ba3fb
commit
817029c0dc
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user