mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Merge pull request #926 from internetee/registry-922
Registrant API domain endpoint
This commit is contained in:
commit
71c74a66f8
4 changed files with 118 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue