66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package dto
|
|
|
|
import "git.yeij.top/AskaEth/Scoreboard/server/internal/domain"
|
|
|
|
// StandingRow 是 GET /api/standings 与 snapshot.standings 的线上结构。
|
|
//
|
|
// 字段名与 web/src/shared/types.ts 的 StandingRow 对齐:大屏与管理端共用一份解析逻辑,
|
|
// 不能再把 domain.StandingsRow 的 points/code/medals 直接下发。
|
|
type StandingRow struct {
|
|
TeamID int64 `json:"teamId"`
|
|
TeamCode string `json:"teamCode"`
|
|
TeamName string `json:"teamName"`
|
|
ShortName *string `json:"shortName"`
|
|
Color *string `json:"color"`
|
|
LogoPath *string `json:"logoPath"`
|
|
Rank int `json:"rank"`
|
|
Gold int `json:"gold"`
|
|
Silver int `json:"silver"`
|
|
Bronze int `json:"bronze"`
|
|
MedalTotal int `json:"medalTotal"`
|
|
TotalPoints float64 `json:"totalPoints"`
|
|
RankChange *int `json:"rankChange"`
|
|
}
|
|
|
|
// StandingRows 把 domain 榜单转换成线上结构。
|
|
// teams 用于补齐颜色/logo 等 domain 榜单没带的展示字段;rankChange 快照没有对比基准,与 REST 一致下发 null。
|
|
func StandingRows(rows []domain.StandingsRow, teams []domain.Team) []StandingRow {
|
|
byID := make(map[int64]domain.Team, len(teams))
|
|
for _, t := range teams {
|
|
byID[t.ID] = t
|
|
}
|
|
|
|
out := make([]StandingRow, 0, len(rows))
|
|
for _, r := range rows {
|
|
t := byID[r.TeamID]
|
|
row := StandingRow{
|
|
TeamID: r.TeamID,
|
|
TeamCode: r.Code,
|
|
TeamName: r.Name,
|
|
ShortName: nilIfEmpty(r.ShortName),
|
|
Rank: r.Rank,
|
|
Gold: r.Gold,
|
|
Silver: r.Silver,
|
|
Bronze: r.Bronze,
|
|
MedalTotal: r.Medals,
|
|
TotalPoints: r.Points,
|
|
RankChange: nil,
|
|
}
|
|
if t.ID != 0 {
|
|
row.Color = nilIfEmpty(t.Color)
|
|
row.LogoPath = nilIfEmpty(t.LogoPath)
|
|
if row.TeamCode == "" {
|
|
row.TeamCode = t.Code
|
|
}
|
|
if row.TeamName == "" {
|
|
row.TeamName = t.Name
|
|
}
|
|
if row.ShortName == nil {
|
|
row.ShortName = nilIfEmpty(t.ShortName)
|
|
}
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
return out
|
|
}
|