autocomplete_sources_controller.rb 1.13 KB
Newer Older
1
class Projects::AutocompleteSourcesController < Projects::ApplicationController
Eric Eastwood's avatar
Eric Eastwood committed
2
  before_action :load_autocomplete_service, except: [:members]
3 4

  def members
5
    render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target)
6 7 8 9 10 11 12 13 14 15 16
  end

  def issues
    render json: @autocomplete_service.issues
  end

  def merge_requests
    render json: @autocomplete_service.merge_requests
  end

  def labels
17
    render json: @autocomplete_service.labels(target)
18 19 20 21 22 23 24
  end

  def milestones
    render json: @autocomplete_service.milestones
  end

  def commands
25
    render json: @autocomplete_service.commands(target, params[:type])
26 27 28 29 30 31 32 33
  end

  private

  def load_autocomplete_service
    @autocomplete_service = ::Projects::AutocompleteService.new(@project, current_user)
  end

34 35 36
  def target
    case params[:type]&.downcase
    when 'issue'
37
      IssuesFinder.new(current_user, project_id: @project.id).execute.find_by(iid: params[:type_id])
38
    when 'mergerequest'
39
      MergeRequestsFinder.new(current_user, project_id: @project.id).execute.find_by(iid: params[:type_id])
40
    when 'commit'
41 42 43 44
      @project.commit(params[:type_id])
    end
  end
end