summaryrefslogtreecommitdiff
path: root/lib/api/resource_state_events.rb
blob: 1c1a90c09a399c7bf899e5d39d4c27a9a055a7d3 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module API
  class ResourceStateEvents < Grape::API::Instance
    include PaginationParams
    helpers ::API::Helpers::NotesHelpers

    before { authenticate! }

    [Issue, MergeRequest].each do |eventable_class|
      eventable_name = eventable_class.to_s.underscore

      params do
        requires :id, type: String, desc: "The ID of a project"
      end
      resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
        desc "Get a list of #{eventable_class.to_s.downcase} resource state events" do
          success Entities::ResourceStateEvent
        end
        params do
          requires :eventable_iid, types: Integer, desc: "The IID of the #{eventable_name}"
          use :pagination
        end

        get ":id/#{eventable_name.pluralize}/:eventable_iid/resource_state_events" do
          eventable = find_noteable(eventable_class, params[:eventable_iid])

          events = ResourceStateEventFinder.new(current_user, eventable).execute

          present paginate(events), with: Entities::ResourceStateEvent
        end

        desc "Get a single #{eventable_class.to_s.downcase} resource state event" do
          success Entities::ResourceStateEvent
        end
        params do
          requires :eventable_iid, types: Integer, desc: "The IID of the #{eventable_name}"
          requires :event_id, type: Integer, desc: 'The ID of a resource state event'
        end
        get ":id/#{eventable_name.pluralize}/:eventable_iid/resource_state_events/:event_id" do
          eventable = find_noteable(eventable_class, params[:eventable_iid])

          event = ResourceStateEventFinder.new(current_user, eventable).find(params[:event_id])

          present event, with: Entities::ResourceStateEvent
        end
      end
    end
  end
end