Merge pull request #926 from internetee/registry-922

Registrant API domain endpoint
This commit is contained in:
Timo Võhmar 2018-08-09 14:03:36 +03:00 committed by GitHub
commit 71c74a66f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 9 deletions

View file

@ -1,18 +1,47 @@
require 'rails5_api_controller_backport'
require 'auth_token/auth_token_decryptor'
module Api
module V1
module Registrant
class DomainsController < BaseController
def index
registrant = ::Registrant.find_by(ident: current_user.registrant_ident)
if registrant
domains = Domain.where(registrant_id: registrant.id)
render json: domains
else
render json: []
limit = params[:limit] || 200
offset = params[:offset] || 0
if limit.to_i > 200 || limit.to_i < 1
render(json: { errors: [{ limit: ['parameter is out of range'] }] },
status: :bad_request) && return
end
if offset.to_i.negative?
render(json: { errors: [{ offset: ['parameter is out of range'] }] },
status: :bad_request) && return
end
@domains = associated_domains(current_user).limit(limit).offset(offset)
render json: @domains
end
def show
domain_pool = associated_domains(current_user)
@domain = domain_pool.find_by(uuid: params[:uuid])
if @domain
render json: @domain
else
render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found
end
end
private
def associated_domains(user)
country_code, ident = user.registrant_ident.split('-')
BusinessRegistryCache.fetch_associated_domains(ident, country_code)
rescue Soap::Arireg::NotAvailableError => error
Rails.logger.fatal("[EXCEPTION] #{error}")
user.domains
end
end
end