# 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