Ü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 {
|
for i, q := range sq {
|
||||||
var answer int
|
|
||||||
|
|
||||||
row := db.QueryRow(query, bid, pid, q.ID)
|
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)
|
return nil, fmt.Errorf("error: *DB.GetGivenAnswers: row.Scan(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
answers[i] = answer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return answers, nil
|
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 {
|
func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion {
|
||||||
questions := make([]resultQuestion, len(sq))
|
questions := make([]resultQuestion, len(sq))
|
||||||
for i, q := range sq {
|
for i, q := range sq {
|
||||||
question := resultQuestion{
|
questions[i].Text = q.Text
|
||||||
Text: q.Text,
|
questions[i].Answers = make([]resultAnswer, len(q.Answers))
|
||||||
Answers: make([]resultAnswer, len(q.Answers)),
|
|
||||||
}
|
|
||||||
|
|
||||||
for j, a := range q.Answers {
|
|
||||||
answer := resultAnswer{Text: a.Text}
|
|
||||||
|
|
||||||
|
for j := range q.Answers {
|
||||||
if j+1 == q.Correct {
|
if j+1 == q.Correct {
|
||||||
answer.Correct = true
|
questions[i].Answers[j].Correct = true
|
||||||
} else {
|
} else {
|
||||||
answer.Correct = false
|
questions[i].Answers[j].Correct = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if j+1 == givenAnswers[i] {
|
if j+1 == givenAnswers[i] {
|
||||||
answer.Chosen = true
|
questions[i].Answers[j].Chosen = true
|
||||||
} else {
|
} else {
|
||||||
answer.Chosen = false
|
questions[i].Answers[j].Chosen = false
|
||||||
}
|
}
|
||||||
question.Answers[j] = answer
|
|
||||||
}
|
}
|
||||||
questions[i] = question
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return questions
|
return questions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user