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:
@@ -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
|
||||
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Admin
|
||||
module Tournaments
|
||||
module Teams
|
||||
class Destroy < EuchreCamp::Action
|
||||
include Deps[teams_repo: 'repositories.teams']
|
||||
|
||||
def handle(request, response)
|
||||
tournament_id = request.params[:id]
|
||||
team_id = request.params[:team_id]
|
||||
|
||||
teams_repo.delete(team_id.to_i)
|
||||
|
||||
response.flash[:message] = "Team removed"
|
||||
response.redirect_to("/admin/tournaments/#{tournament_id}")
|
||||
rescue StandardError => e
|
||||
response.flash[:error] = "Failed to remove team: #{e.message}"
|
||||
response.redirect_to("/admin/tournaments/#{tournament_id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Admin
|
||||
module Tournaments
|
||||
module Teams
|
||||
class Edit < EuchreCamp::Action
|
||||
include Deps[
|
||||
teams_repo: 'repositories.teams',
|
||||
players_repo: 'repositories.players',
|
||||
events_repo: 'repositories.events'
|
||||
]
|
||||
|
||||
def handle(request, response)
|
||||
tournament_id = request.params[:id]
|
||||
team_id = request.params[:team_id]
|
||||
|
||||
tournament = events_repo.by_id(tournament_id)
|
||||
team = teams_repo.teams.by_pk(team_id).one
|
||||
players = players_repo.all
|
||||
|
||||
response.render(view,
|
||||
tournament: tournament,
|
||||
team: team,
|
||||
players: players
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Admin
|
||||
module Tournaments
|
||||
module Teams
|
||||
class Update < EuchreCamp::Action
|
||||
include Deps[teams_repo: 'repositories.teams']
|
||||
|
||||
def handle(request, response)
|
||||
tournament_id = request.params[:id]
|
||||
team_id = request.params[:team_id]
|
||||
params = request.params.to_h
|
||||
|
||||
update_params = {
|
||||
team_name: params[:team_name],
|
||||
player_1_id: params[:player_1_id]&.to_i,
|
||||
player_2_id: params[:player_2_id]&.to_i
|
||||
}
|
||||
|
||||
teams_repo.update(team_id.to_i, update_params)
|
||||
|
||||
response.flash[:message] = "Team updated"
|
||||
response.redirect_to("/admin/tournaments/#{tournament_id}")
|
||||
rescue StandardError => e
|
||||
response.flash[:error] = "Failed to update team: #{e.message}"
|
||||
response.redirect_to("/admin/tournaments/#{tournament_id}/teams/#{team_id}/edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user