Add name server API

#661
This commit is contained in:
Artur Beljajev 2018-02-22 12:44:24 +02:00
parent 1fe520261f
commit 69c32546de
5 changed files with 120 additions and 65 deletions

View file

@ -10,20 +10,27 @@ module Repp
requires :id, type: String, allow_blank: false
requires :attributes, type: Hash do
requires :hostname, type: String, allow_blank: false
requires :ipv4, type: Array
requires :ipv6, type: Array
end
end
end
current_user.registrar.nameservers.where(hostname: params[:data][:id]).each do |nameserver|
nameserver.hostname = params[:data][:attributes][:hostname]
nameserver.ipv4 = params[:data][:attributes][:ipv4]
nameserver.ipv6 = params[:data][:attributes][:ipv6]
nameserver.save!
end
old_nameserver = current_user.registrar.nameservers.find_by(hostname: params[:data][:id])
error!({ errors: [{ title: "Hostname #{params[:data][:id]} does not exist" }] }, 404) unless old_nameserver
status 204
body false
@response = {}
new_nameserver = old_nameserver.dup
new_nameserver.hostname = params[:data][:attributes][:hostname]
new_nameserver.ipv4 = params[:data][:attributes][:ipv4]
new_nameserver.ipv6 = params[:data][:attributes][:ipv6]
error!({ errors: [{ title: 'Invalid params' }] }, 400) unless new_nameserver.valid?
current_user.registrar.replace_nameserver(old_nameserver, new_nameserver)
status 200
@response = { data: { type: 'nameserver',
id: new_nameserver.hostname, attributes: params[:data][:attributes] } }
end
end
end