mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Extract Contact create BL from EPP controller
This commit is contained in:
parent
248c984443
commit
a33cc40d59
3 changed files with 73 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
require 'deserializers/xml/contact_update'
|
require 'deserializers/xml/contact_update'
|
||||||
|
require 'deserializers/xml/contact_create'
|
||||||
module Epp
|
module Epp
|
||||||
class ContactsController < BaseController
|
class ContactsController < BaseController
|
||||||
before_action :find_contact, only: [:info, :update, :delete]
|
before_action :find_contact, only: [:info, :update, :delete]
|
||||||
|
@ -21,13 +21,13 @@ module Epp
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize! :create, Epp::Contact
|
authorize! :create, Epp::Contact
|
||||||
frame = params[:parsed_frame]
|
|
||||||
@contact = Epp::Contact.new(frame, current_user.registrar)
|
|
||||||
|
|
||||||
@contact.add_legal_file_to_new(frame)
|
@contact = Epp::Contact.new(params[:parsed_frame], current_user.registrar)
|
||||||
@contact.generate_code
|
collected_data = ::Deserializers::Xml::ContactCreate.new(params[:parsed_frame])
|
||||||
|
|
||||||
if @contact.save
|
action = Actions::ContactCreate.new(@contact, collected_data.legal_document)
|
||||||
|
|
||||||
|
if action.call
|
||||||
if !address_processing? && address_given?
|
if !address_processing? && address_given?
|
||||||
@response_code = 1100
|
@response_code = 1100
|
||||||
@response_description = t('epp.contacts.completed_without_address')
|
@response_description = t('epp.contacts.completed_without_address')
|
||||||
|
|
44
app/models/actions/contact_create.rb
Normal file
44
app/models/actions/contact_create.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
module Actions
|
||||||
|
class ContactCreate
|
||||||
|
attr_reader :contact, :legal_document
|
||||||
|
|
||||||
|
def initialize(contact, legal_document)
|
||||||
|
@contact = contact
|
||||||
|
@legal_document = legal_document
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
maybe_remove_address
|
||||||
|
maybe_attach_legal_doc
|
||||||
|
commit
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_remove_address
|
||||||
|
return if Contact.address_processing?
|
||||||
|
|
||||||
|
contact.city = nil
|
||||||
|
contact.zip = nil
|
||||||
|
contact.street = nil
|
||||||
|
contact.state = nil
|
||||||
|
contact.country_code = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_attach_legal_doc
|
||||||
|
return unless legal_document
|
||||||
|
|
||||||
|
doc = LegalDocument.create(
|
||||||
|
documentable_type: Contact,
|
||||||
|
document_type: legal_document[:type], body: legal_document[:body]
|
||||||
|
)
|
||||||
|
|
||||||
|
contact.legal_documents = [doc]
|
||||||
|
contact.legal_document_id = doc.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def commit
|
||||||
|
contact.generate_code
|
||||||
|
|
||||||
|
contact.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
lib/deserializers/xml/contact_create.rb
Normal file
23
lib/deserializers/xml/contact_create.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
require 'deserializers/xml/legal_document'
|
||||||
|
require 'deserializers/xml/ident'
|
||||||
|
require 'deserializers/xml/contact'
|
||||||
|
|
||||||
|
module Deserializers
|
||||||
|
module Xml
|
||||||
|
class ContactCreate
|
||||||
|
attr_reader :frame
|
||||||
|
|
||||||
|
def initialize(frame)
|
||||||
|
@frame = frame
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact
|
||||||
|
@contact ||= ::Deserializers::Xml::Contact.new(frame).call
|
||||||
|
end
|
||||||
|
|
||||||
|
def legal_document
|
||||||
|
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue