63 lines
2.1 KiB
Ruby
63 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module EuchreCamp
|
|
module Actions
|
|
module Admin
|
|
module Tournaments
|
|
class Show < EuchreCamp::Action
|
|
include Deps[
|
|
events_repo: 'repositories.events',
|
|
participants_repo: 'repositories.event_participants',
|
|
teams_repo: 'repositories.teams',
|
|
rounds_repo: 'repositories.tournament_rounds',
|
|
players_repo: 'repositories.players'
|
|
]
|
|
|
|
def handle(request, response)
|
|
tournament_id = request.params[:id]
|
|
tournament = events_repo.by_id(tournament_id)
|
|
user = current_user(request)
|
|
|
|
# Check authorization - tournament admin can manage their tournaments
|
|
unless user && EuchreCamp::Services::Authorization.can?(user, :manage_tournament, tournament)
|
|
response.flash[:error] = 'Access denied'
|
|
response.redirect_to '/rankings'
|
|
return
|
|
end
|
|
|
|
# Get all registered participants for this tournament
|
|
participants = participants_repo.by_event(tournament_id)
|
|
participant_ids = participants.map { |p| p[:player_id] }
|
|
|
|
# Get registered players details
|
|
players = if participant_ids.any?
|
|
players_repo.players.where(id: participant_ids).to_a
|
|
else
|
|
[]
|
|
end
|
|
|
|
# Get ALL players for the registration dropdown (not yet registered)
|
|
all_players = players_repo.all
|
|
available_players = all_players.reject { |p| participant_ids.include?(p[:id]) }
|
|
|
|
# Get teams
|
|
teams = teams_repo.by_event(tournament_id)
|
|
|
|
# Get rounds
|
|
rounds = rounds_repo.by_event(tournament_id)
|
|
|
|
response.render(view,
|
|
tournament: tournament,
|
|
players: players,
|
|
available_players: available_players,
|
|
teams: teams,
|
|
rounds: rounds,
|
|
participants: participants
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|