sorarebuddy/model/game_player.go

62 lines
1.8 KiB
Go
Raw Normal View History

2024-05-23 04:18:54 +00:00
package model
import (
"git.lehouerou.net/laurent/sorare/football"
)
type GamePlayer struct {
GameId string `bun:"game_id,pk" json:"gameId"`
PlayerSlug string `bun:"player_slug,pk" json:"playerSlug"`
Status string `bun:"status" json:"status"`
TeamSlug string `bun:"team_slug" json:"teamSlug"`
Game *Game `bun:"rel:has-one,join:game_id=id" json:"game"`
Player *Player `bun:"rel:has-one,join:player_slug=slug" json:"player"`
Score *GamePlayerScore `bun:"rel:has-one,join:game_id=game_id,join:player_slug=player_slug" json:"score"`
}
func ExtractPlayersFromGameWithFormation(
gameWithFormation football.GameFormation,
) []GamePlayer {
var res []GamePlayer
for _, p := range gameWithFormation.HomeFormation.Bench {
res = append(res, GamePlayer{
GameId: gameWithFormation.Id.Value,
PlayerSlug: p.Slug,
TeamSlug: gameWithFormation.HomeTeam.Team.Slug,
Status: "bench",
})
}
for _, p := range gameWithFormation.HomeFormation.StartingLineup {
for _, q := range p {
res = append(res, GamePlayer{
GameId: gameWithFormation.Id.Value,
PlayerSlug: q.Slug,
TeamSlug: gameWithFormation.HomeTeam.Team.Slug,
Status: "starting",
})
}
}
for _, p := range gameWithFormation.AwayFormation.Bench {
res = append(res, GamePlayer{
GameId: gameWithFormation.Id.Value,
PlayerSlug: p.Slug,
TeamSlug: gameWithFormation.AwayTeam.Team.Slug,
Status: "bench",
})
}
for _, p := range gameWithFormation.AwayFormation.StartingLineup {
for _, q := range p {
res = append(res, GamePlayer{
GameId: gameWithFormation.Id.Value,
PlayerSlug: q.Slug,
TeamSlug: gameWithFormation.AwayTeam.Team.Slug,
Status: "starting",
})
}
}
return res
}