server/libfic/theme_export.go

57 lines
1.3 KiB
Go
Raw Normal View History

2018-01-09 14:16:16 +00:00
package fic
import (
"fmt"
)
type ExportedExercice struct {
Title string `json:"title"`
2018-01-18 10:07:50 +00:00
URLId string `json:"urlid"`
2018-01-09 14:16:16 +00:00
Gain int64 `json:"gain"`
Coeff float64 `json:"curcoeff"`
Solved int64 `json:"solved"`
Tried int64 `json:"tried"`
}
type exportedTheme struct {
Name string `json:"name"`
2018-01-18 10:07:50 +00:00
URLId string `json:"urlid"`
2018-01-09 14:16:16 +00:00
Authors string `json:"authors"`
Intro string `json:"intro"`
Exercices map[string]ExportedExercice `json:"exercices"`
}
func ExportThemes() (interface{}, error) {
if themes, err := GetThemes(); err != nil {
return nil, err
} else {
ret := map[string]exportedTheme{}
for _, theme := range themes {
if exercices, err := theme.GetExercices(); err != nil {
return nil, err
} else {
exos := map[string]ExportedExercice{}
for _, exercice := range exercices {
exos[fmt.Sprintf("%d", exercice.Id)] = ExportedExercice{
exercice.Title,
2018-01-18 10:07:50 +00:00
exercice.URLId,
2018-01-09 14:16:16 +00:00
exercice.Gain,
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
}
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name,
2018-01-18 10:07:50 +00:00
theme.URLId,
2018-01-09 14:16:16 +00:00
theme.Authors,
theme.Intro,
exos,
}
}
}
return ret, nil
}
}