module Public class TournamentGroupsController < WebBaseController before_action :require_login! before_action :set_tournament def create Tournaments::Entitlements.new(@club).assert_writable! position = @tournament.groups.maximum(:position).to_i + 1 name = params.dig(:tournament_group, :name).presence || "Girone #{('A'.ord + position).chr}" @tournament.groups.create!(name: name, position: position) redirect_to public_tournament_path(@tournament, tab: "struttura"), notice: t("flash.tournaments.group_added") rescue Tournaments::EntitlementError => e redirect_to public_club_billing_path(@club), alert: e.message end def destroy Tournaments::Entitlements.new(@club).assert_writable! @tournament.groups.find(params[:group_id]).destroy! redirect_to public_tournament_path(@tournament, tab: "struttura"), notice: t("flash.tournaments.group_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 end end