Aggiunge i tornei con hub, pagina pubblica e tabellone per semifinali e finali.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 15:05:57 +02:00
co-authored by Cursor
parent d52434fb2e
commit a1f4c24a43
124 changed files with 6979 additions and 91 deletions
@@ -0,0 +1,40 @@
module Tournaments
class FillKnockoutSources
def self.call(tournament)
new(tournament).call
end
def initialize(tournament)
@tournament = tournament
end
def call
@tournament.matches.find_each do |match|
next if match.home_source_kind.blank? && match.away_source_kind.blank?
home = resolve(match, :home)
away = resolve(match, :away)
attrs = {}
attrs[:home_participant] = home if home && match.home_participant_id.blank?
attrs[:away_participant] = away if away && match.away_participant_id.blank?
match.update!(attrs) if attrs.any?
end
end
private
def resolve(match, side)
kind = match.public_send("#{side}_source_kind")
case kind
when "winner_match"
source = Match.find_by(id: match.public_send("#{side}_source_match_id"))
source&.winner_participant
when "group_rank"
group = TournamentGroup.find_by(id: match.public_send("#{side}_source_group_id"))
rank = match.public_send("#{side}_source_rank").to_i
return nil unless group && rank.positive?
Tournaments::Standings.call(group)[rank - 1]&.participant
end
end
end
end