mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
REPP: Move domain transfer info to rails API format
This commit is contained in:
parent
6c655e1179
commit
d1ab61f424
4 changed files with 68 additions and 52 deletions
60
app/controllers/repp/v1/domains_controller.rb
Normal file
60
app/controllers/repp/v1/domains_controller.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
module Repp
|
||||
module V1
|
||||
class DomainsController < BaseController
|
||||
before_action :set_authorized_domain, only: [:transfer_info]
|
||||
|
||||
def index
|
||||
records = current_user.registrar.domains
|
||||
domains = records.limit(limit).offset(offset)
|
||||
domains = domains.pluck(:name) unless params[:details] == 'true'
|
||||
|
||||
render_success(data: { domains: domains, total_number_of_records: records.count })
|
||||
end
|
||||
|
||||
def transfer_info
|
||||
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
||||
zip country_code statuses]
|
||||
|
||||
data = {
|
||||
domain: @domain.name,
|
||||
registrant: @domain.registrant.as_json(only: contact_fields),
|
||||
admin_contacts: @domain.admin_contacts.map { |c| c.as_json(only: contact_fields) },
|
||||
tech_contacts: @domain.tech_contacts.map { |c| c.as_json(only: contact_fields) },
|
||||
}
|
||||
|
||||
render_success(data: data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def transfer_info_params
|
||||
params.require(:id)
|
||||
params.permit(:id)
|
||||
end
|
||||
|
||||
def set_authorized_domain
|
||||
@epp_errors ||= []
|
||||
h = {}
|
||||
h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id]
|
||||
@domain = Domain.find_by!(h)
|
||||
|
||||
return if @domain.transfer_code.eql?(request.headers['Auth-Code'])
|
||||
|
||||
@epp_errors << { code: '401', msg: I18n.t('errors.messages.epp_authorization_error') }
|
||||
handle_errors
|
||||
end
|
||||
|
||||
def limit
|
||||
params[:limit] || 200
|
||||
end
|
||||
|
||||
def offset
|
||||
params[:offset] || 0
|
||||
end
|
||||
|
||||
def index_params
|
||||
params.permit(:limit, :offset, :details)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue