Remove code duplication

This commit is contained in:
Maciej Szlosarczyk 2018-10-02 12:23:23 +03:00
parent 63837c40ba
commit 28304559fd
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765

View file

@ -9,8 +9,7 @@ module Api
def create def create
if @domain.apply_registry_lock if @domain.apply_registry_lock
serializer = Serializers::RegistrantApi::Domain.new(@domain) render json: serialized_domain(@domain)
render json: serializer.to_json
else else
render json: { errors: [{ base: ['Domain cannot be locked'] }] }, render json: { errors: [{ base: ['Domain cannot be locked'] }] },
status: :unprocessable_entity status: :unprocessable_entity
@ -19,8 +18,7 @@ module Api
def destroy def destroy
if @domain.remove_registry_lock if @domain.remove_registry_lock
serializer = Serializers::RegistrantApi::Domain.new(@domain) render json: serialized_domain(@domain)
render json: serializer.to_json
else else
render json: { errors: [{ base: ['Domain is not locked'] }] }, render json: { errors: [{ base: ['Domain is not locked'] }] },
status: :unprocessable_entity status: :unprocessable_entity
@ -46,6 +44,11 @@ module Api
] }, ] },
status: :unauthorized and return status: :unauthorized and return
end end
def serialized_domain(domain)
serializer = Serializers::RegistrantApi::Domain.new(domain)
serializer.to_json
end
end end
end end
end end