Skip to content

Commit 18cec7c

Browse files
committed
included different contetend types in round data
1 parent 010cb27 commit 18cec7c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

quiz/types.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ type Question struct {
4848
}
4949

5050
type DisplayableContent struct {
51-
Type ContentType
52-
Text string
51+
Type ContentType `json:"type"`
52+
Text string `json:"text"`
5353
}
5454

5555
type ContentType uint8
@@ -60,12 +60,13 @@ const (
6060
)
6161

6262
type Round struct {
63-
Question string `json:"question"`
64-
Answers []string `json:"answers"`
65-
Correct int `json:"correct,omitempty"`
66-
Current int `json:"current_round"`
67-
Max int `json:"max_round"`
68-
Category string `json:"category"`
63+
Question DisplayableContent `json:"question"`
64+
Answers []DisplayableContent `json:"answers"`
65+
Correct int `json:"correct,omitempty"`
66+
Current int `json:"current_round"`
67+
Max int `json:"max_round"`
68+
Group string `json:"group"`
69+
Category string `json:"category"`
6970
}
7071

7172
type RoundSummary struct {
@@ -204,26 +205,28 @@ func (c Category) GetRounds(n int) []*Round {
204205
}
205206

206207
func (q Question) ToRound() Round {
207-
var answers []string
208+
var answers []DisplayableContent
208209

209210
// select one correct answer
210211
if len(q.Correct) > 1 {
211212
rand.Shuffle(len(q.Correct), func(i, j int) {
212213
q.Correct[i], q.Correct[j] = q.Correct[j], q.Correct[i]
213214
})
214-
answers = append(answers, q.Correct[rand.Intn(len(q.Correct)-1)].Text)
215+
answers = append(answers, q.Correct[rand.Intn(len(q.Correct)-1)])
215216
} else {
216-
answers = append(answers, q.Correct[0].Text)
217+
answers = append(answers, q.Correct[0])
217218
}
218219

219220
// select up to 3 wrong answers
220221
if len(q.Wrong) > 3 {
221222
rand.Shuffle(len(q.Wrong), func(i, j int) {
222223
q.Wrong[i], q.Wrong[j] = q.Wrong[j], q.Wrong[i]
223224
})
224-
}
225-
for _, a := range q.Wrong[:3] {
226-
answers = append(answers, a.Text)
225+
for _, a := range q.Wrong[:3] {
226+
answers = append(answers, a)
227+
}
228+
} else {
229+
answers = append(answers, q.Wrong...)
227230
}
228231

229232
var correct int
@@ -235,7 +238,7 @@ func (q Question) ToRound() Round {
235238
})
236239

237240
return Round{
238-
Question: q.Question.Text,
241+
Question: q.Question,
239242
Answers: answers,
240243
Correct: correct + 1,
241244
}

0 commit comments

Comments
 (0)