Refactor series handling in backend to include player context in Toss, Ban, Pick, and Record actions. Update service methods to accept player parameters, enhancing authorization checks and ensuring proper team actions. Modify integration tests to reflect new method signatures and improve tournament hydration logic in the store. Enhance frontend components to support new series features and improve user experience with live match navigation.
This commit is contained in:
@@ -612,6 +612,9 @@ func (s *Store) GetTournament(ctx context.Context, id string) (domain.Tournament
|
||||
if err == nil {
|
||||
err = json.Unmarshal(body, &out)
|
||||
}
|
||||
if err == nil {
|
||||
err = s.hydrateTournament(ctx, &out)
|
||||
}
|
||||
return out, mapError(err)
|
||||
}
|
||||
|
||||
@@ -622,9 +625,43 @@ func (s *Store) GetTournamentByEvent(ctx context.Context, eventID string) (domai
|
||||
if err == nil {
|
||||
err = json.Unmarshal(body, &out)
|
||||
}
|
||||
if err == nil {
|
||||
err = s.hydrateTournament(ctx, &out)
|
||||
}
|
||||
return out, mapError(err)
|
||||
}
|
||||
|
||||
func (s *Store) hydrateTournament(ctx context.Context, tournament *domain.Tournament) error {
|
||||
rows, err := s.pool.Query(ctx, `SELECT body FROM series WHERE tournament_id=$1`, tournament.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
live := make(map[string]domain.Series)
|
||||
for rows.Next() {
|
||||
var body []byte
|
||||
var series domain.Series
|
||||
if err := rows.Scan(&body); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(body, &series); err != nil {
|
||||
return err
|
||||
}
|
||||
live[series.ID] = series
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
for round := range tournament.Rounds {
|
||||
for match := range tournament.Rounds[round] {
|
||||
if series, ok := live[tournament.Rounds[round][match].ID]; ok {
|
||||
tournament.Rounds[round][match] = series
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) SaveDraft(ctx context.Context, id, kind string, value any, expectedVersion int) error {
|
||||
body, _ := json.Marshal(value)
|
||||
if expectedVersion < 0 {
|
||||
|
||||
Reference in New Issue
Block a user