# frozen_string_literal: true module EuchreCamp module Actions module Admin module Tournaments class Update < EuchreCamp::Action include Deps[repo: 'repositories.events'] def handle(request, response) tournament_id = request.params[:id] params = request.params.to_h update_params = { name: params[:name], description: params[:description], event_date: params[:event_date] ? Time.parse(params[:event_date]) : nil, format: params[:format], max_participants: params[:max_participants]&.to_i } repo.update(tournament_id, update_params) response.flash[:message] = "Tournament updated" response.redirect_to("/admin/tournaments/#{tournament_id}") rescue StandardError => e response.flash[:error] = "Failed to update: #{e.message}" response.redirect_to("/admin/tournaments/#{tournament_id}/edit") end end end end end end