53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package sorare_utils
|
|
|
|
import (
|
|
"git.lehouerou.net/laurent/sorare/football"
|
|
|
|
"git.lehouerou.net/laurent/sorarebuddy/model"
|
|
)
|
|
|
|
func ExtractPlayersFromGameWithFormation(
|
|
gameWithFormation football.GameWithFormation,
|
|
) []model.CreateOrUpdateGamePlayersParams {
|
|
var res []model.CreateOrUpdateGamePlayersParams
|
|
for _, p := range gameWithFormation.HomeFormation.Bench {
|
|
res = append(res, model.CreateOrUpdateGamePlayersParams{
|
|
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, model.CreateOrUpdateGamePlayersParams{
|
|
GameID: gameWithFormation.Id.Value,
|
|
PlayerSlug: q.Slug,
|
|
TeamSlug: gameWithFormation.HomeTeam.Team.Slug,
|
|
Status: "starting",
|
|
})
|
|
}
|
|
}
|
|
for _, p := range gameWithFormation.AwayFormation.Bench {
|
|
res = append(res, model.CreateOrUpdateGamePlayersParams{
|
|
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, model.CreateOrUpdateGamePlayersParams{
|
|
GameID: gameWithFormation.Id.Value,
|
|
PlayerSlug: q.Slug,
|
|
TeamSlug: gameWithFormation.AwayTeam.Team.Slug,
|
|
Status: "starting",
|
|
})
|
|
}
|
|
}
|
|
|
|
return res
|
|
|
|
}
|