<commit_before>class ColleagueshipsController < ApplicationController
  before_action :require_user

  def search
    term = "%#{params[:term]}%"
    if term.present?
      @colleagues = Colleagueship.search(current_user, term, 20)
    else
      @colleagues = {}
    end
    render json: @colleagues.map { |c|
      {
        id: c.id,
        username: c.username,
        company_short: c.company_short,
        avatar_full_url: c.avatar.url(:mini_quadrat),
        first_name: c.first_name, last_name: c.last_name
      }
    }
  end

  def create
    @colleagueship = current_user.colleagueships.build(colleague_id: params[:colleague_id])
    if @colleagueship.save
      respond_to do |format|
        format.html { render "created", layout: false }
        format.json { render json: { colleagueship_id: @colleagueship.id } }
      end
    else
      render "failed", layout: false
    end
  end

  def destroy
    @colleagueship = current_user.colleagueships.where(colleague_id: params[:id]).first
    @colleagueship.destroy
    render json: { status: :deleted }
  end
end<commit_msg>Bug fix: unfriending directly after friending on profile page<commit_after>class ColleagueshipsController < ApplicationController
  before_action :require_user

  def search
    term = "%#{params[:term]}%"
    if term.present?
      @colleagues = Colleagueship.search(current_user, term, 20)
    else
      @colleagues = {}
    end
    render json: @colleagues.map { |c|
      {
        id: c.id,
        username: c.username,
        company_short: c.company_short,
        avatar_full_url: c.avatar.url(:mini_quadrat),
        first_name: c.first_name, last_name: c.last_name
      }
    }
  end

  def create
    @colleagueship = current_user.colleagueships.build(colleague_id: params[:colleague_id])
    if @colleagueship.save
      respond_to do |format|
        format.html { render 'created', layout: false }
        format.json { render json: { colleagueship_id: @colleagueship.colleague_id } }
      end
    else
      render 'failed', layout: false
    end
  end

  def destroy
    @colleagueship = current_user.colleagueships.where(colleague_id: params[:id]).first
    @colleagueship.destroy
    render json: { status: :deleted }
  end
end
{'fraction_non_alphanumeric': 0.09946476360392506, 'fraction_numerical': 0.001784121320249777, 'mean_word_length': 2.9420035149384884, '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': '1205116', 'n_tokens_mistral': 748, 'n_tokens_neox': 723, 'n_words': 157}