added free agents
This commit is contained in:
@@ -79,6 +79,7 @@ type FixtureResultPlayerStats struct {
|
||||
HasMercyRuled *int
|
||||
WasMercyRuled *int
|
||||
PeriodsPlayed *int
|
||||
IsFreeAgent bool `bun:"is_free_agent,default:false"`
|
||||
|
||||
FixtureResult *FixtureResult `bun:"rel:belongs-to,join:fixture_result_id=id"`
|
||||
Player *Player `bun:"rel:belongs-to,join:player_id=id"`
|
||||
@@ -87,10 +88,11 @@ type FixtureResultPlayerStats struct {
|
||||
|
||||
// PlayerWithPlayStatus is a helper struct for overview display
|
||||
type PlayerWithPlayStatus struct {
|
||||
Player *Player
|
||||
Played bool
|
||||
IsManager bool
|
||||
Stats *FixtureResultPlayerStats // Period 3 (final cumulative) stats, nil if no result
|
||||
Player *Player
|
||||
Played bool
|
||||
IsManager bool
|
||||
IsFreeAgent bool
|
||||
Stats *FixtureResultPlayerStats // Period 3 (final cumulative) stats, nil if no result
|
||||
}
|
||||
|
||||
// InsertFixtureResult stores a new match result with all player stats in a single transaction.
|
||||
@@ -489,6 +491,12 @@ func GetFixtureTeamRosters(
|
||||
// Build maps of player IDs that played and their period 3 stats
|
||||
playedPlayerIDs := map[int]bool{}
|
||||
playerStatsByID := map[int]*FixtureResultPlayerStats{}
|
||||
freeAgentPlayerIDs := map[int]bool{}
|
||||
// Track free agents by team side for roster inclusion
|
||||
freeAgentsByTeam := map[string]map[int]*FixtureResultPlayerStats{} // "home"/"away" -> playerID -> stats
|
||||
freeAgentsByTeam["home"] = map[int]*FixtureResultPlayerStats{}
|
||||
freeAgentsByTeam["away"] = map[int]*FixtureResultPlayerStats{}
|
||||
|
||||
if result != nil {
|
||||
for _, ps := range result.PlayerStats {
|
||||
if ps.PlayerID != nil {
|
||||
@@ -496,10 +504,29 @@ func GetFixtureTeamRosters(
|
||||
if ps.PeriodNum == 3 {
|
||||
playerStatsByID[*ps.PlayerID] = ps
|
||||
}
|
||||
if ps.IsFreeAgent {
|
||||
freeAgentPlayerIDs[*ps.PlayerID] = true
|
||||
if ps.PeriodNum == 3 {
|
||||
freeAgentsByTeam[ps.Team][*ps.PlayerID] = ps
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build a set of roster player IDs so we can skip them when adding free agents
|
||||
rosterPlayerIDs := map[int]bool{}
|
||||
for _, r := range homeRosters {
|
||||
if r.Player != nil {
|
||||
rosterPlayerIDs[r.Player.ID] = true
|
||||
}
|
||||
}
|
||||
for _, r := range awayRosters {
|
||||
if r.Player != nil {
|
||||
rosterPlayerIDs[r.Player.ID] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Build home roster with play status and stats
|
||||
for _, r := range homeRosters {
|
||||
played := false
|
||||
@@ -532,5 +559,29 @@ func GetFixtureTeamRosters(
|
||||
})
|
||||
}
|
||||
|
||||
// Add free agents who played but are not on the team roster
|
||||
for team, faStats := range freeAgentsByTeam {
|
||||
for playerID, stats := range faStats {
|
||||
if rosterPlayerIDs[playerID] {
|
||||
continue // Already on the roster, skip
|
||||
}
|
||||
if stats.Player == nil {
|
||||
// Try to load the player
|
||||
player, err := GetPlayer(ctx, tx, playerID)
|
||||
if err != nil {
|
||||
continue // Skip if we can't load
|
||||
}
|
||||
stats.Player = player
|
||||
}
|
||||
rosters[team] = append(rosters[team], &PlayerWithPlayStatus{
|
||||
Player: stats.Player,
|
||||
Played: true,
|
||||
IsManager: false,
|
||||
IsFreeAgent: true,
|
||||
Stats: stats,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return rosters, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user