module Public class TournamentParticipantsController < WebBaseController before_action :require_login! before_action :set_tournament def create Tournaments::Entitlements.new(@club).assert_writable! @tournament.participants.create!(participant_params) redirect_to public_tournament_path(@tournament, tab: "squadre"), notice: t("flash.tournaments.participant_added") rescue Tournaments::EntitlementError => e redirect_to public_club_billing_path(@club), alert: e.message rescue ActiveRecord::RecordInvalid => e redirect_to public_tournament_path(@tournament, tab: "squadre"), alert: e.record.errors.full_messages.join(", ") end def update Tournaments::Entitlements.new(@club).assert_writable! participant = @tournament.participants.find(params[:participant_id]) participant.update!(participant_params) file = params.dig(:tournament_participant, :logo_file) participant.logo_file.attach(file) if file.present? redirect_to public_tournament_path(@tournament, tab: "squadre"), notice: t("flash.tournaments.participant_updated") rescue Tournaments::EntitlementError => e redirect_to public_club_billing_path(@club), alert: e.message rescue ActiveRecord::RecordInvalid => e redirect_to public_tournament_path(@tournament, tab: "squadre"), alert: e.record.errors.full_messages.join(", ") end def destroy Tournaments::Entitlements.new(@club).assert_writable! @tournament.participants.find(params[:participant_id]).destroy! redirect_to public_tournament_path(@tournament, tab: "squadre"), notice: t("flash.tournaments.participant_removed") rescue Tournaments::EntitlementError => e redirect_to public_club_billing_path(@club), alert: e.message end private def set_tournament @tournament = Tournament.find(params[:id]) @club = @tournament.club require_club_owner!(@club) end def participant_params permitted = params.require(:tournament_participant).permit(:name, :group_id, :primary_color, :logo_url, :source_team_id) permitted[:group_id] = permitted[:group_id].presence if permitted.key?(:group_id) permitted end end end