<commit_before>class SlackWebhooksController < ApplicationController

  skip_before_action :verify_authenticity_token, only: :create

  # before_action :authorize_team
  before_action :ensure_valid_command

  def create
    result = operation.call(add_video_params)
    if result.success?
      render text: result.message, status: :created
    else
      Rails.logger.error { "#{result.errors}" }
      render text: result.errors, status: :unprocessable_entity
    end
  end

  private

  def add_video_params
    {
      team: team,
      user: user,
      playlist: playlist,
      dj: dj,
      command: params[:text]
    }
  end

  def authorize_team
    if team.token != params[:token]
      head :unprocessable_entity
    end
  end

  def team
    @_team ||= Team.find_or_create_by(slack_id: params[:team_id])
  end

  def player
    @_player ||= Player.find_or_create_by(team_id: team.id)
  end

  def user
    @_user ||= User.find_or_create_by(slack_id: params[:user_id], team_id: team.id) do |u|
      u.name = params[:user_name]
    end
  end
<commit_msg>rename controller helper method for clarity<commit_after>class SlackWebhooksController < ApplicationController

  skip_before_action :verify_authenticity_token, only: :create

  # before_action :authorize_team
  before_action :ensure_valid_command

  def create
    result = operation.call(create_params)
    if result.success?
      render text: result.message, status: :created
    else
      Rails.logger.error { "#{result.errors}" }
      render text: result.errors, status: :unprocessable_entity
    end
  end

  private

  def create_params
    {
      team: team,
      user: user,
      playlist: playlist,
      dj: dj,
      command: params[:text]
    }
  end

  def authorize_team
    if team.token != params[:token]
      head :unprocessable_entity
    end
  end

  def team
    @_team ||= Team.find_or_create_by(slack_id: params[:team_id])
  end

  def player
    @_player ||= Player.find_or_create_by(team_id: team.id)
  end

  def user
    @_user ||= User.find_or_create_by(slack_id: params[:user_id], team_id: team.id) do |u|
      u.name = params[:user_name]
    end
  end

{'fraction_non_alphanumeric': 0.09183673469387756, 'fraction_numerical': 0.0, 'mean_word_length': 3.1802325581395348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551114', 'n_tokens_mistral': 736, 'n_tokens_neox': 714, 'n_words': 165}