mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
REPP: Move nameservers endpoint to Rails API format
This commit is contained in:
parent
a782b19d28
commit
c31dc15207
3 changed files with 47 additions and 45 deletions
40
app/controllers/repp/v1/registrar/nameservers_controller.rb
Normal file
40
app/controllers/repp/v1/registrar/nameservers_controller.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Repp
|
||||
module V1
|
||||
module Registrar
|
||||
class NameserversController < BaseController
|
||||
before_action :verify_nameserver_existance, only: %i[update]
|
||||
|
||||
def update
|
||||
domains = current_user.registrar
|
||||
.replace_nameservers(hostname, hostname_params[:data][:attributes])
|
||||
|
||||
render_success(data: data_format_for_success(domains))
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
handle_errors(e.record)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def data_format_for_success(affected_domains)
|
||||
{ type: 'nameserver', id: params[:data][:attributes][:hostname],
|
||||
attributes: params[:data][:attributes], affected_domains: affected_domains }
|
||||
end
|
||||
|
||||
def hostname_params
|
||||
params.require(:data).require(%i[type id])
|
||||
params.require(:data).require(:attributes).require(%i[hostname ipv4 ipv6])
|
||||
|
||||
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
|
||||
end
|
||||
|
||||
def hostname
|
||||
hostname_params[:data][:id]
|
||||
end
|
||||
|
||||
def verify_nameserver_existance
|
||||
current_user.registrar.nameservers.find_by!(hostname: hostname)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue