1# frozen_string_literal: true
2
3class AdminAction
4 class LaunchSnikket
5 def self.call(customer_id, reply:, snikket_repo:, **)
6 reply.call(
7 FormTemplate.render("snikket_launch")
8 ).then { |response|
9 domain = response.form.field("domain").value.to_s
10 IQ_MANAGER.write(Snikket::Launch.new(
11 nil, CONFIG[:snikket_hosting_api], domain: domain
12 )).then do |launched|
13 Snikket::CustomerInstance.for(customer_id, domain, launched)
14 end
15 }.then { |instance| save(snikket_repo, reply, instance) }
16 end
17
18 def self.save(snikket_repo, reply, instance)
19 snikket_repo.put(instance).then do
20 reply.call(FormTemplate.render(
21 "snikket_launched",
22 instance: instance
23 ))
24 end
25 end
26 end
27end