themes.json: Use a exercice list instead of hash

This commit is contained in:
nemunaire 2023-01-24 14:15:48 +01:00
commit ef1eafb789
11 changed files with 82 additions and 82 deletions

View file

@ -10,6 +10,7 @@ var GlobalScoreCoefficient float64 = 1
// exportedExercice is a structure representing a challenge, as exposed to players.
type exportedExercice struct {
Id int64 `json:"id"`
Title string `json:"title"`
Headline string `json:"headline,omitempty"`
URLId string `json:"urlid"`
@ -22,16 +23,16 @@ type exportedExercice struct {
// exportedTheme is a structure representing a Theme, as exposed to players.
type exportedTheme struct {
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Headline string `json:"headline,omitempty"`
Intro string `json:"intro"`
Image string `json:"image,omitempty"`
PartnerImage string `json:"partner_img,omitempty"`
PartnerLink string `json:"partner_href,omitempty"`
PartnerText string `json:"partner_txt,omitempty"`
Exercices map[string]exportedExercice `json:"exercices"`
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Headline string `json:"headline,omitempty"`
Intro string `json:"intro"`
Image string `json:"image,omitempty"`
PartnerImage string `json:"partner_img,omitempty"`
PartnerLink string `json:"partner_href,omitempty"`
PartnerText string `json:"partner_txt,omitempty"`
Exercices []exportedExercice `json:"exercices"`
}
// Exportedthemes exports themes from the database, to be displayed to players.
@ -44,10 +45,11 @@ func ExportThemes() (interface{}, error) {
if exercices, err := theme.GetExercices(); err != nil {
return nil, err
} else {
exos := map[string]exportedExercice{}
exos := []exportedExercice{}
for _, exercice := range exercices {
tags, _ := exercice.GetTags()
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{
exos = append(exos, exportedExercice{
exercice.Id,
exercice.Title,
exercice.Headline,
exercice.URLId,
@ -56,7 +58,7 @@ func ExportThemes() (interface{}, error) {
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
}
})
}
imgpath := ""