2016-12-27 20:12:17 +00:00
|
|
|
package fic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
// exportedTeam is a structure representing a Team, as exposed to players.
|
2021-09-04 18:53:03 +00:00
|
|
|
type ExportedTeam struct {
|
2021-11-22 14:35:07 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Color string `json:"color"`
|
|
|
|
Rank int `json:"rank"`
|
|
|
|
Points float64 `json:"score"`
|
|
|
|
Members []*Member `json:"members,omitempty"`
|
|
|
|
ExternalId string `json:"external_id,omitempty"`
|
2016-12-27 20:12:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
// Exportedteam creates the structure to respond as teams.json.
|
2021-09-04 18:53:03 +00:00
|
|
|
func ExportTeams(includeMembers bool) (ret map[string]ExportedTeam, err error) {
|
2021-11-22 14:35:07 +00:00
|
|
|
var teams []*Team
|
2018-03-09 18:07:08 +00:00
|
|
|
var rank map[int64]int
|
|
|
|
|
|
|
|
if teams, err = GetTeams(); err != nil {
|
|
|
|
return
|
|
|
|
} else if rank, err = GetRank(); err != nil {
|
2016-12-27 20:12:17 +00:00
|
|
|
return nil, err
|
|
|
|
} else {
|
2021-09-04 18:53:03 +00:00
|
|
|
ret = map[string]ExportedTeam{}
|
2016-12-27 20:12:17 +00:00
|
|
|
for _, team := range teams {
|
2017-01-12 10:52:51 +00:00
|
|
|
points, _ := team.GetPoints()
|
2021-11-22 14:35:07 +00:00
|
|
|
var members []*Member
|
2020-01-30 17:43:44 +00:00
|
|
|
if includeMembers {
|
|
|
|
if members, err = team.GetMembers(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-09-04 18:53:03 +00:00
|
|
|
ret[fmt.Sprintf("%d", team.Id)] = ExportedTeam{
|
2017-01-12 10:52:51 +00:00
|
|
|
team.Name,
|
2021-09-04 18:52:41 +00:00
|
|
|
fmt.Sprintf("#%06x", team.Color),
|
2017-01-12 10:52:51 +00:00
|
|
|
rank[team.Id],
|
2021-09-06 09:58:03 +00:00
|
|
|
points * GlobalScoreCoefficient,
|
2020-01-30 17:43:44 +00:00
|
|
|
members,
|
2021-09-03 15:23:00 +00:00
|
|
|
team.ExternalId,
|
2016-12-27 20:12:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
return
|
2016-12-27 20:12:17 +00:00
|
|
|
}
|
|
|
|
}
|