17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/moogle/commands/create_link.rb', line 17
def call
link_model = opts :link_model, Moogle::Link
target_model = opts :target_model, Moogle::Target
event_class = opts :event_class, Moogle::Events::LinkCreated
representer = opts :representer, Moogle::LinkRepresenter
target = target_model.get request.target_id
unless target
raise '404 Not found target'
end
link = link_model.create(
target: target,
receiver_ref: request.receiver_ref,
message_kind: request.message_kind)
raise link.errors.full_messages.join('. ') unless link.saved?
link_rep = link.dup.extend representer
return event_class.new request.create_child_uuids.merge(link: link_rep)
rescue => e
e.extend Moogle::Error
raise e
end
|