Class: WikiPages::EventCreateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/wiki_pages/event_create_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(author) ⇒ EventCreateService

Returns a new instance of EventCreateService.

Parameters:

  • author (User)

    The event author

Raises:

  • (ArgumentError)

6
7
8
9
10
# File 'app/services/wiki_pages/event_create_service.rb', line 6

def initialize(author)
  raise ArgumentError, 'author must not be nil' unless author

  @author = author
end

Instance Method Details

#execute(slug, page, action, event_fingerprint) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'app/services/wiki_pages/event_create_service.rb', line 12

def execute(slug, page, action, event_fingerprint)
  wiki_page_meta = WikiPage::Meta.find_or_create(slug, page)

  event = ::EventCreateService.new.wiki_event(wiki_page_meta, author, action, event_fingerprint)

  ServiceResponse.success(payload: { event: event })
rescue ::EventCreateService::IllegalActionError, ::ActiveRecord::ActiveRecordError => e
  ServiceResponse.error(message: e.message, payload: { error: e })
end