fic: Add Order, Help and Type values in struct

This commit is contained in:
nemunaire 2021-08-30 18:33:14 +02:00
commit 74e8c3801a
16 changed files with 134 additions and 110 deletions

View file

@ -27,50 +27,46 @@ type myTeamHint struct {
Cost int64 `json:"cost"`
}
type myTeamFlag struct {
Label string `json:"label"`
Placeholder string `json:"placeholder,omitempty"`
Separator string `json:"separator,omitempty"`
NbLines uint64 `json:"nb_lines,omitempty"`
IgnoreOrder bool `json:"ignore_order,omitempty"`
IgnoreCase bool `json:"ignore_case,omitempty"`
Multiline bool `json:"multiline,omitempty"`
ValidatorRe *string `json:"validator_regexp,omitempty"`
Solved *time.Time `json:"found,omitempty"`
Soluce string `json:"soluce,omitempty"`
Choices map[string]string `json:"choices,omitempty"`
ChoicesCost int64 `json:"choices_cost,omitempty"`
Order int8 `json:"order"`
Label string `json:"label"`
Type string `json:"type,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Help string `json:"help,omitempty"`
Separator string `json:"separator,omitempty"`
NbLines uint64 `json:"nb_lines,omitempty"`
IgnoreOrder bool `json:"ignore_order,omitempty"`
IgnoreCase bool `json:"ignore_case,omitempty"`
Multiline bool `json:"multiline,omitempty"`
ValidatorRe *string `json:"validator_regexp,omitempty"`
Solved *time.Time `json:"found,omitempty"`
PSolved *time.Time `json:"part_solved,omitempty"`
Soluce string `json:"soluce,omitempty"`
Justify bool `json:"justify,omitempty"`
Choices map[string]interface{} `json:"choices,omitempty"`
ChoicesCost int64 `json:"choices_cost,omitempty"`
}
type myTeamMCQJustifiedChoice struct {
Label string `json:"label"`
Value bool `json:"value,omitempty"`
Justification myTeamFlag `json:"justification,omitempty"`
}
type myTeamMCQ struct {
Title string `json:"title"`
Justify bool `json:"justify,omitempty"`
Choices map[int64]interface{} `json:"choices,omitempty"`
Solved *time.Time `json:"solved,omitempty"`
PSolved *time.Time `json:"part_solved,omitempty"`
Soluce string `json:"soluce,omitempty"`
}
type myTeamExercice struct {
ThemeId int64 `json:"theme_id"`
Statement string `json:"statement"`
Overview string `json:"overview,omitempty"`
Finished string `json:"finished,omitempty"`
Hints []myTeamHint `json:"hints,omitempty"`
Gain int `json:"gain"`
Files []myTeamFile `json:"files,omitempty"`
Flags map[int64]myTeamFlag `json:"flags,omitempty"`
MCQs map[int64]myTeamMCQ `json:"mcqs,omitempty"`
SolveDist int64 `json:"solve_dist,omitempty"`
SolvedTime *time.Time `json:"solved_time,omitempty"`
SolvedRank int64 `json:"solved_rank,omitempty"`
Tries int64 `json:"tries,omitempty"`
TotalTries int64 `json:"total_tries,omitempty"`
VideoURI string `json:"video_uri,omitempty"`
Issue string `json:"issue,omitempty"`
IssueKind string `json:"issuekind,omitempty"`
ThemeId int64 `json:"theme_id"`
Statement string `json:"statement"`
Overview string `json:"overview,omitempty"`
Finished string `json:"finished,omitempty"`
Hints []myTeamHint `json:"hints,omitempty"`
Gain int `json:"gain"`
Files []myTeamFile `json:"files,omitempty"`
Flags map[int]myTeamFlag `json:"flags,omitempty"`
SolveDist int64 `json:"solve_dist,omitempty"`
SolvedTime *time.Time `json:"solved_time,omitempty"`
SolvedRank int64 `json:"solved_rank,omitempty"`
Tries int64 `json:"tries,omitempty"`
TotalTries int64 `json:"total_tries,omitempty"`
VideoURI string `json:"video_uri,omitempty"`
Issue string `json:"issue,omitempty"`
IssueKind string `json:"issuekind,omitempty"`
}
type myTeam struct {
Id int64 `json:"team_id"`
@ -179,8 +175,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
// Expose exercice flags
justifiedMCQ := map[int64]myTeamFlag{}
exercice.Flags = map[int64]myTeamFlag{}
justifiedMCQ := map[int]myTeamFlag{}
exercice.Flags = map[int]myTeamFlag{}
if flags, err := e.GetFlagKeys(); err != nil {
return nil, err
@ -188,6 +184,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
for _, k := range flags {
var flag myTeamFlag
flag.Order = k.Order
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(k) {
// Dependancy missing, skip the flag for now
continue
@ -225,7 +223,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
if choices, err := k.GetChoices(); err != nil {
return nil, err
} else if t == nil || WChoiceCoefficient < 0 || k.ChoicesCost == 0 || t.SeeChoices(k) {
flag.Choices = map[string]string{}
flag.Choices = map[string]interface{}{}
for _, c := range choices {
flag.Choices[c.Value] = c.Label
}
@ -243,10 +241,6 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
}
}
// Expose exercice MCQs
exercice.MCQs = map[int64]myTeamMCQ{}
if mcqs, err := e.GetMCQ(); err != nil {
return nil, err
} else {
@ -256,9 +250,11 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
continue
}
m := myTeamMCQ{
Title: mcq.Title,
Choices: map[int64]interface{}{},
m := myTeamFlag{
Type: "mcq",
Label: mcq.Title,
Order: mcq.Order,
Choices: map[string]interface{}{},
}
soluce := ""
@ -292,12 +288,12 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
jc.Value = e.Response
}
m.Choices[e.Id] = jc
m.Choices[strconv.Itoa(e.Id)] = jc
} else {
m.Choices[e.Id] = e.Label
m.Choices[strconv.Itoa(e.Id)] = e.Label
}
} else {
m.Choices[e.Id] = e.Label
m.Choices[strconv.Itoa(e.Id)] = e.Label
}
}
@ -311,7 +307,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
m.PSolved = nil
}
exercice.MCQs[mcq.Id] = m
exercice.Flags[mcq.Id] = m
}
}