debian-mirror-gitlab/app/services/wiki_pages/event_create_service.rb

29 lines
785 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module WikiPages
class EventCreateService
# @param [User] author The event author
def initialize(author)
raise ArgumentError, 'author must not be nil' unless author
@author = author
end
2020-10-24 23:57:45 +05:30
def execute(slug, page, action, event_fingerprint)
2020-05-24 23:13:21 +05:30
event = Event.transaction do
wiki_page_meta = WikiPage::Meta.find_or_create(slug, page)
2020-10-24 23:57:45 +05:30
::EventCreateService.new.wiki_event(wiki_page_meta, author, action, event_fingerprint)
2020-05-24 23:13:21 +05:30
end
ServiceResponse.success(payload: { event: event })
rescue ::EventCreateService::IllegalActionError, ::ActiveRecord::ActiveRecordError => e
ServiceResponse.error(message: e.message, payload: { error: e })
end
private
attr_reader :author
end
end