2020-07-16 17:10:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class ResourceStateEvents < ::API::Base
|
2020-07-16 17:10:05 -04:00
|
|
|
include PaginationParams
|
|
|
|
helpers ::API::Helpers::NotesHelpers
|
|
|
|
|
|
|
|
before { authenticate! }
|
|
|
|
|
2022-09-15 11:13:49 -04:00
|
|
|
Helpers::ResourceEventsHelpers.eventable_types.each do |eventable_type, details|
|
|
|
|
parent_type = eventable_type.parent_class.to_s.underscore
|
|
|
|
eventables_str = eventable_type.to_s.underscore.pluralize
|
|
|
|
human_eventable_str = eventable_type.to_s.underscore.humanize.downcase
|
|
|
|
feature_category = details[:feature_category]
|
2020-07-16 17:10:05 -04:00
|
|
|
|
|
|
|
params do
|
2022-09-15 11:13:49 -04:00
|
|
|
requires :id, type: String, desc: "The ID of a #{parent_type}"
|
2020-07-16 17:10:05 -04:00
|
|
|
end
|
2022-09-15 11:13:49 -04:00
|
|
|
resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc "Get a list of #{human_eventable_str} resource state events" do
|
2020-07-16 17:10:05 -04:00
|
|
|
success Entities::ResourceStateEvent
|
|
|
|
end
|
|
|
|
params do
|
2022-09-15 11:13:49 -04:00
|
|
|
requires :eventable_id, types: Integer, desc: "The #{details[:id_field]} of the #{human_eventable_str}"
|
2020-07-16 17:10:05 -04:00
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
|
2022-09-15 11:13:49 -04:00
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_state_events", feature_category: feature_category, urgency: :low do
|
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
2020-07-16 17:10:05 -04:00
|
|
|
|
|
|
|
events = ResourceStateEventFinder.new(current_user, eventable).execute
|
|
|
|
|
|
|
|
present paginate(events), with: Entities::ResourceStateEvent
|
|
|
|
end
|
|
|
|
|
2022-09-15 11:13:49 -04:00
|
|
|
desc "Get a single #{human_eventable_str} resource state event" do
|
2020-07-16 17:10:05 -04:00
|
|
|
success Entities::ResourceStateEvent
|
|
|
|
end
|
|
|
|
params do
|
2022-09-15 11:13:49 -04:00
|
|
|
requires :eventable_id, types: Integer, desc: "The #{details[:id_field]} of the #{human_eventable_str}"
|
2020-07-16 17:10:05 -04:00
|
|
|
requires :event_id, type: Integer, desc: 'The ID of a resource state event'
|
|
|
|
end
|
2022-09-15 11:13:49 -04:00
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_state_events/:event_id", feature_category: feature_category do
|
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
2020-07-16 17:10:05 -04:00
|
|
|
|
|
|
|
event = ResourceStateEventFinder.new(current_user, eventable).find(params[:event_id])
|
|
|
|
|
|
|
|
present event, with: Entities::ResourceStateEvent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|