From 28304559fda1955b729a9d89494f5d7aa45050cf Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 12:23:23 +0300 Subject: [PATCH] Remove code duplication --- .../api/v1/registrant/registry_locks_controller.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb index 5100cd748..d431b5cd0 100644 --- a/app/controllers/api/v1/registrant/registry_locks_controller.rb +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -9,8 +9,7 @@ module Api def create if @domain.apply_registry_lock - serializer = Serializers::RegistrantApi::Domain.new(@domain) - render json: serializer.to_json + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain cannot be locked'] }] }, status: :unprocessable_entity @@ -19,8 +18,7 @@ module Api def destroy if @domain.remove_registry_lock - serializer = Serializers::RegistrantApi::Domain.new(@domain) - render json: serializer.to_json + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain is not locked'] }] }, status: :unprocessable_entity @@ -46,6 +44,11 @@ module Api ] }, status: :unauthorized and return end + + def serialized_domain(domain) + serializer = Serializers::RegistrantApi::Domain.new(domain) + serializer.to_json + end end end end