mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
parent
d951a90bf8
commit
c53d5542f6
6 changed files with 99 additions and 21 deletions
|
@ -5,10 +5,10 @@ module Repp
|
|||
resource 'registrar/nameservers' do
|
||||
put '/' do
|
||||
params do
|
||||
requires :data, type: Hash do
|
||||
requires :data, type: Hash, allow_blank: false do
|
||||
requires :type, type: String, allow_blank: false
|
||||
requires :id, type: String, allow_blank: false
|
||||
requires :attributes, type: Hash do
|
||||
requires :attributes, type: Hash, allow_blank: false do
|
||||
requires :hostname, type: String, allow_blank: false
|
||||
requires :ipv4, type: Array
|
||||
requires :ipv6, type: Array
|
||||
|
@ -16,21 +16,28 @@ module Repp
|
|||
end
|
||||
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
|
||||
hostname = params[:data][:id]
|
||||
|
||||
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]
|
||||
unless current_user.registrar.nameservers.exists?(hostname: hostname)
|
||||
error!({ errors: [{ title: "Hostname #{hostname} does not exist" }] }, 404)
|
||||
end
|
||||
|
||||
error!({ errors: [{ title: 'Invalid params' }] }, 400) unless new_nameserver.valid?
|
||||
new_attributes = {
|
||||
hostname: params[:data][:attributes][:hostname],
|
||||
ipv4: params[:data][:attributes][:ipv4],
|
||||
ipv6: params[:data][:attributes][:ipv6],
|
||||
}
|
||||
|
||||
current_user.registrar.replace_nameserver(old_nameserver, new_nameserver)
|
||||
begin
|
||||
current_user.registrar.replace_nameservers(hostname, new_attributes)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400)
|
||||
end
|
||||
|
||||
status 200
|
||||
@response = { data: { type: 'nameserver',
|
||||
id: new_nameserver.hostname, attributes: params[:data][:attributes] } }
|
||||
id: params[:data][:attributes][:hostname],
|
||||
attributes: params[:data][:attributes] } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue