blob: d008d1b9e97f00ad2a6b1b47742f4a53999d70b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# frozen_string_literal: true
module API
class Suggestions < Grape::API
before { authenticate! }
resource :suggestions do
desc 'Apply suggestion patch in the Merge Request it was created' do
success Entities::Suggestion
end
params do
requires :id, type: String, desc: 'The suggestion ID'
end
put ':id/apply' do
suggestion = Suggestion.find_by_id(params[:id])
not_found! unless suggestion
authorize! :apply_suggestion, suggestion
result = ::Suggestions::ApplyService.new(current_user).execute(suggestion)
if result[:status] == :success
present suggestion, with: Entities::Suggestion, current_user: current_user
else
http_status = result[:http_status] || 400
render_api_error!(result[:message], http_status)
end
end
end
end
end
|