feat(tournaments): add partnership tracking and tournament management

Implement comprehensive partnership tracking system and tournament
management features including round-robin, single/double elimination,
and Swiss system pairings.

Changes:
- Add partnership_games and partnership_stats tables
- Implement PartnershipTracker service for recording partnership data
- Add tournament generator with multiple formats
- Create tournament management actions and views
- Add acceptance tests for partnership tracking
- Fix PartnershipTracker to use single snapshot per player per match
- Fix round-robin test to query by round_number instead of hardcoded ID

Note: All 8 acceptance tests now passing
This commit is contained in:
2026-03-27 12:25:34 -07:00
parent cb47b9da99
commit ac858f1e6d
55 changed files with 2591 additions and 0 deletions
@@ -0,0 +1,62 @@
# frozen_string_literal: true
module EuchreCamp
module Actions
module Admin
module Tournaments
module Teams
class Create < EuchreCamp::Action
include Deps[
teams_repo: 'repositories.teams',
players_repo: 'repositories.players',
participants_repo: 'repositories.event_participants'
]
def handle(request, response)
tournament_id = request.params[:id]
params = request.params.to_h
player_1_id = params[:player_1_id]&.to_i
player_2_id = params[:player_2_id]&.to_i
team_name = params[:team_name]
if player_1_id.nil? || player_2_id.nil?
response.flash[:error] = "Please select both players"
response.redirect_to("/admin/tournaments/#{tournament_id}")
return
end
if player_1_id == player_2_id
response.flash[:error] = "Players must be different"
response.redirect_to("/admin/tournaments/#{tournament_id}")
return
end
# Ensure players are registered as participants
[player_1_id, player_2_id].each do |player_id|
existing = participants_repo.by_event(tournament_id).find { |p| p[:player_id] == player_id }
unless existing
participants_repo.register_player(tournament_id, player_id)
end
end
# Create the team
team = teams_repo.create(
event_id: tournament_id,
player_1_id: player_1_id,
player_2_id: player_2_id,
team_name: team_name || "Team #{player_1_id}-#{player_2_id}"
)
response.flash[:message] = "Team created successfully"
response.redirect_to("/admin/tournaments/#{tournament_id}")
rescue StandardError => e
response.flash[:error] = "Failed to create team: #{e.message}"
response.redirect_to("/admin/tournaments/#{tournament_id}")
end
end
end
end
end
end
end