Add domain index action (without pagination yet)

This commit is contained in:
Maciej Szlosarczyk 2018-07-30 15:09:48 +03:00
parent 13562aeb06
commit 10d42a0d74
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
5 changed files with 155 additions and 4 deletions

View file

@ -3,10 +3,15 @@ require 'rails5_api_controller_backport'
module Api
module V1
module Registrant
class DomainsController < ActionController::API
class DomainsController < BaseController
def index
@domains = associated_domains(current_user)
render json: @domains
end
def show
@domain = Domain.find_by(uuid: params[:uuid])
domain_pool = associated_domains(current_user)
@domain = domain_pool.find_by(uuid: params[:uuid])
if @domain
render json: @domain
@ -14,6 +19,17 @@ module Api
render json: { errors: ["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.to_s}")
user.domains
end
end
end
end