Backend: extract file generation and team renaming in dedicated files

This commit is contained in:
nemunaire 2016-03-06 18:57:08 +01:00 committed by Pierre-Olivier Mercier
commit 1c62f61bf0
8 changed files with 261 additions and 140 deletions

View file

@ -16,49 +16,6 @@ var ApiThemesRouting = map[string]DispatchFunction{
"DELETE": deletionTheme,
}
type exportedExercice struct {
Title string `json:"title"`
Gain int64 `json:"gain"`
Solved int64 `json:"solved"`
Tried int64 `json:"tried"`
}
type exportedTheme struct {
Name string `json:"name"`
Authors string `json:"authors"`
Exercices map[string]exportedExercice `json:"exercices"`
}
func exportThemes() (interface{}, error) {
if themes, err := fic.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.SolvedCount(),
exercice.TriedTeamCount(),
}
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name,
theme.Authors[:len(theme.Authors)-1],
exos,
}
}
}
return ret, nil
}
}
func bindingFiles() (string, error) {
if files, err := fic.GetFiles(); err != nil {
return "", err
@ -114,7 +71,7 @@ func listTheme(args []string, body []byte) (interface{}, error) {
if args[0] == "files-bindings" {
return bindingFiles()
} else if args[0] == "themes.json" {
return exportThemes()
return fic.ExportThemes()
} else {
return getTheme(args)
}