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
parent aefd078ebf
commit 1c62f61bf0
8 changed files with 261 additions and 140 deletions

View file

@ -1,6 +1,7 @@
package fic
import (
"fmt"
"time"
)
@ -158,3 +159,35 @@ func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
return true, *tm, *nb + 1
}
}
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 := GetTeams(); err != nil {
return nil, err
} else if rank, err := 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
}
}