57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package fic
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type ExportedExercice struct {
|
|
Title string `json:"title"`
|
|
URLId string `json:"urlid"`
|
|
Gain int64 `json:"gain"`
|
|
Coeff float64 `json:"curcoeff"`
|
|
Solved int64 `json:"solved"`
|
|
Tried int64 `json:"tried"`
|
|
}
|
|
|
|
type exportedTheme struct {
|
|
Name string `json:"name"`
|
|
URLId string `json:"urlid"`
|
|
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,
|
|
exercice.URLId,
|
|
exercice.Gain,
|
|
exercice.Coefficient,
|
|
exercice.SolvedCount(),
|
|
exercice.TriedTeamCount(),
|
|
}
|
|
}
|
|
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
|
theme.Name,
|
|
theme.URLId,
|
|
theme.Authors,
|
|
theme.Intro,
|
|
exos,
|
|
}
|
|
}
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
}
|