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