Backend: extract file generation and team renaming in dedicated files
This commit is contained in:
parent
aefd078ebf
commit
1c62f61bf0
8 changed files with 261 additions and 140 deletions
|
|
@ -25,9 +25,9 @@ func genStats() (interface{}, error) {
|
|||
if exercices, err := theme.GetExercices(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
exos := map[string]exportedExercice{}
|
||||
exos := map[string]fic.ExportedExercice{}
|
||||
for _, exercice := range exercices {
|
||||
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{
|
||||
exos[fmt.Sprintf("%d", exercice.Id)] = fic.ExportedExercice{
|
||||
exercice.Title,
|
||||
exercice.Gain,
|
||||
exercice.SolvedCount(),
|
||||
|
|
|
|||
|
|
@ -29,37 +29,6 @@ func nginxGenTeam() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
type exportedTeam struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Rank int `json:"rank"`
|
||||
Points int64 `json:"score"`
|
||||
}
|
||||
|
||||
func exportTeams() (interface{}, error) {
|
||||
if teams, err := fic.GetTeams(); err != nil {
|
||||
return nil, err
|
||||
} else if rank, err := fic.GetRank(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret := map[string]exportedTeam{}
|
||||
for _, team := range teams {
|
||||
if points, err := team.GetPoints(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret[fmt.Sprintf("%d", team.Id)] = exportedTeam{
|
||||
team.Name,
|
||||
fmt.Sprintf("#%x", team.Color),
|
||||
rank[team.Id],
|
||||
points,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
||||
func bindingTeams() (string, error) {
|
||||
if teams, err := fic.GetTeams(); err != nil {
|
||||
return "", err
|
||||
|
|
@ -118,13 +87,13 @@ func listTeam(args []string, body []byte) (interface{}, error) {
|
|||
}
|
||||
} else if len(args) == 1 {
|
||||
if args[0] == "teams.json" {
|
||||
return exportTeams()
|
||||
return fic.ExportTeams()
|
||||
} else if args[0] == "nginx" {
|
||||
return nginxGenTeam()
|
||||
} else if args[0] == "binding" {
|
||||
return bindingTeams()
|
||||
} else if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
return nil, err
|
||||
return fic.GetTeamByInitialName(args[0])
|
||||
} else if team, err := fic.GetTeam(tid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue