2020-05-11 23:09:31 -04:00
|
|
|
# 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-07-20 08:09:34 -04:00
|
|
|
def execute(slug, page, action, event_fingerprint)
|
2021-08-20 17:10:36 -04:00
|
|
|
wiki_page_meta = WikiPage::Meta.find_or_create(slug, page)
|
2020-05-11 23:09:31 -04:00
|
|
|
|
2021-08-20 17:10:36 -04:00
|
|
|
event = ::EventCreateService.new.wiki_event(wiki_page_meta, author, action, event_fingerprint)
|
2020-05-11 23:09:31 -04:00
|
|
|
|
|
|
|
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
|