Commit 9b95fe78 authored by Peter Leitzen's avatar Peter Leitzen

Move finding autocompletion targets into AutocompleteService

parent 19f97d2a
class Projects::AutocompleteSourcesController < Projects::ApplicationController class Projects::AutocompleteSourcesController < Projects::ApplicationController
before_action :load_autocomplete_service, except: [:members] before_action :load_autocomplete_service
def members def members
render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target) render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target)
...@@ -32,13 +32,6 @@ class Projects::AutocompleteSourcesController < Projects::ApplicationController ...@@ -32,13 +32,6 @@ class Projects::AutocompleteSourcesController < Projects::ApplicationController
end end
def target def target
case params[:type]&.downcase @autocomplete_service.target(params[:type], params[:type_id])
when 'issue'
IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:type_id]) || @project.issues.build
when 'mergerequest'
MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:type_id]) || @project.merge_requests.build
when 'commit'
@project.commit(params[:type_id])
end
end end
end end
...@@ -51,5 +51,16 @@ module Projects ...@@ -51,5 +51,16 @@ module Projects
QuickActions::InterpretService.new(project, current_user).available_commands(noteable) QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
end end
def target(type, type_id)
case type&.downcase
when 'issue'
IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build
when 'mergerequest'
MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build
when 'commit'
project.commit(type_id)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment