Move DomainDelete to interactor design pattern

This commit is contained in:
Alex Sherman 2020-11-25 14:26:53 +05:00
parent 42b9adbf44
commit d406334926
4 changed files with 41 additions and 10 deletions

View file

@ -0,0 +1,7 @@
module DomainDeleteInteraction
class Base < ActiveInteraction::Base
object :domain,
class: Domain,
description: 'Domain to delete'
end
end

View file

@ -0,0 +1,11 @@
module DomainDeleteInteraction
class Delete < :Base
def execute
::PaperTrail.request.whodunnit = "interaction - #{self.class.name}"
WhoisRecord.where(domain_id: domain.id).destroy_all
domain.destroy
compose(NotifyRegistrar, inputs)
end
end
end

View file

@ -0,0 +1,12 @@
module DomainDeleteInteraction
class NotifyRegistrar < Delete
def execute
bye_bye = domain.versions.last
domain.registrar.notifications.create!(
text: "#{I18n.t(:domain_deleted)}: #{domain.name}",
attached_obj_id: bye_bye.id,
attached_obj_type: bye_bye.class.to_s
)
end
end
end

View file

@ -3,15 +3,16 @@ class DomainDeleteJob < Que::Job
def run(domain_id) def run(domain_id)
domain = Domain.find(domain_id) domain = Domain.find(domain_id)
::PaperTrail.request.whodunnit = "job - #{self.class.name}" DomainDeleteInteraction::Delete.run(domain: domain)
WhoisRecord.where(domain_id: domain.id).destroy_all # ::PaperTrail.request.whodunnit = "job - #{self.class.name}"
# WhoisRecord.where(domain_id: domain.id).destroy_all
domain.destroy #
bye_bye = domain.versions.last # domain.destroy
domain.registrar.notifications.create!( # bye_bye = domain.versions.last
text: "#{I18n.t(:domain_deleted)}: #{domain.name}", # domain.registrar.notifications.create!(
attached_obj_id: bye_bye.id, # text: "#{I18n.t(:domain_deleted)}: #{domain.name}",
attached_obj_type: bye_bye.class.to_s # attached_obj_id: bye_bye.id,
) # attached_obj_type: bye_bye.class.to_s
# )
end end
end end