refactoring: deligious return domain wich related to registrar function in concern

This commit is contained in:
Oleg Hasjanov 2021-07-06 11:07:09 +03:00
parent fee6b897af
commit 13650ae37e
2 changed files with 25 additions and 20 deletions

View file

@ -1,19 +1,21 @@
module Admin
class DomainsController < BaseController
include AdminDomains
before_action :set_domain, only: %i[show edit update keep]
authorize_resource
def index
params[:q] ||= {}
domains = if params[:statuses_contains]
Domain.includes(:registrar, :registrant).where(
'domains.statuses @> ?::varchar[]', "{#{params[:statuses_contains].join(',')}}"
)
else
Domain.includes(:registrar, :registrant)
end
if params[:statuses_contains]
domains = Domain.includes(:registrar, :registrant).where(
"domains.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
domains = Domain.includes(:registrar, :registrant)
end
domains = return_domains_which_related_to_registrars
domains = get_domains_which_related_to_registrars
normalize_search_parameters do
@q = domains.search(params[:q])
@ -61,7 +63,7 @@ module Admin
redirect_to [:admin, @domain]
else
build_associations
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(', ')
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(", ")
render 'edit'
end
end
@ -107,7 +109,7 @@ module Admin
begin
end_time = params[:q][:valid_to_lteq].try(:to_date)
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
rescue StandardError
rescue
logger.warn('Invalid date')
end
@ -115,15 +117,5 @@ module Admin
params[:q][:valid_to_lteq] = ca_cache
end
def get_domains_which_related_to_registrars
if params[:registrar_id_eq]
Domain.includes(:registrar, :registrant).where(
registrar: params[:registrar_id_eq]
)
else
Domain.includes(:registrar, :registrant)
end
end
end
end

View file

@ -0,0 +1,13 @@
module AdminDomains
extend ActiveSupport::Concern
def return_domains_which_related_to_registrars
if params[:registrar_id_eq]
domains = Domain.includes(:registrar, :registrant).where(
registrar: params[:registrar_id_eq]
)
else
domains = Domain.includes(:registrar, :registrant)
end
end
end