From 8755fbdbf47866d915b9c8e11a9e30aa53d530c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 12 Oct 2020 14:55:44 +0300 Subject: [PATCH] REPP: compose success data in new method --- .../repp/v1/contacts_controller.rb | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/repp/v1/contacts_controller.rb b/app/controllers/repp/v1/contacts_controller.rb index e7e5c73cf..b70e67c61 100644 --- a/app/controllers/repp/v1/contacts_controller.rb +++ b/app/controllers/repp/v1/contacts_controller.rb @@ -5,15 +5,12 @@ module Repp ## GET /repp/v1/contacts def index - limit = params[:limit] || 200 - offset = params[:offset] || 0 - record_count = current_user.registrar.contacts.count show_addresses = Contact.address_processing? && params[:details] == 'true' - contacts = showable_contacts(params[:details], limit, offset, show_addresses) + contacts = showable_contacts(params[:details], params[:limit] || 200, + params[:offset] || 0, show_addresses) - resp = { contacts: contacts, total_number_of_records: record_count } - render(json: resp, status: :ok) + render(json: { contacts: contacts, total_number_of_records: record_count }, status: :ok) end ## GET /repp/v1/contacts/1 @@ -31,17 +28,16 @@ module Repp ## POST /repp/v1/contacts def create - @legal_doc = params[:legal_documents] - @contact = Epp::Contact.new(contact_params_with_address, current_user.registrar, epp: false) - action = Actions::ContactCreate.new(@contact, @legal_doc, contact_ident_params) + action = Actions::ContactCreate.new(@contact, params[:legal_documents], + contact_ident_params) + unless action.call handle_errors(@contact) return end - render_success(code: opt_addr? ? 1100 : nil, data: { contact: { id: @contact.code } }, - message: opt_addr? ? I18n.t('epp.contacts.completed_without_address') : nil) + render_success(create_update_success_data) end ## PUT /repp/v1/contacts/1 @@ -55,8 +51,7 @@ module Repp return end - render_success(code: opt_addr? ? 1100 : nil, data: { contact: { id: @contact.code } }, - message: opt_addr? ? I18n.t('epp.contacts.completed_without_address') : nil) + render_success(create_update_success_data) end def contact_addr_present? @@ -65,6 +60,11 @@ module Repp contact_addr_params[:addr].keys.any? end + def create_update_success_body + { code: opt_addr? ? 1100 : nil, data: { contact: { id: @contact.code } }, + message: opt_addr? ? I18n.t('epp.contacts.completed_without_address') : nil } + end + def showable_contacts(details, limit, offset, addresses) contacts = current_user.registrar.contacts.limit(limit).offset(offset) unless addresses