mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Merge pull request #1750 from internetee/registrant-api-fetch-improvements
Registrant API: Include total domain count
This commit is contained in:
commit
0d09327493
7 changed files with 51 additions and 26 deletions
|
@ -19,15 +19,16 @@ module Api
|
|||
end
|
||||
|
||||
contacts = current_user_contacts.limit(limit).offset(offset)
|
||||
serialized_contacts = contacts.collect { |contact| serialize_contact(contact) }
|
||||
serialized_contacts = contacts.collect { |contact| serialize_contact(contact, false) }
|
||||
render json: serialized_contacts
|
||||
end
|
||||
|
||||
def show
|
||||
contact = current_user_contacts.find_by(uuid: params[:uuid])
|
||||
links = params[:links] == 'true'
|
||||
|
||||
if contact
|
||||
render json: serialize_contact(contact)
|
||||
render json: serialize_contact(contact, links)
|
||||
else
|
||||
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
|
||||
end
|
||||
|
@ -85,7 +86,7 @@ module Api
|
|||
contact.registrar.notify(action)
|
||||
end
|
||||
|
||||
render json: serialize_contact(contact)
|
||||
render json: serialize_contact(contact, false)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -96,8 +97,8 @@ module Api
|
|||
current_registrant_user.direct_contacts
|
||||
end
|
||||
|
||||
def serialize_contact(contact)
|
||||
Serializers::RegistrantApi::Contact.new(contact).to_json
|
||||
def serialize_contact(contact, links)
|
||||
Serializers::RegistrantApi::Contact.new(contact, links).to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ module Api
|
|||
def index
|
||||
limit = params[:limit] || 200
|
||||
offset = params[:offset] || 0
|
||||
simple = params[:simple] == 'true' || false
|
||||
|
||||
if limit.to_i > 200 || limit.to_i < 1
|
||||
render(json: { errors: [{ limit: ['parameter is out of range'] }] },
|
||||
|
@ -18,21 +19,20 @@ module Api
|
|||
status: :bad_request) && return
|
||||
end
|
||||
|
||||
@domains = current_user_domains.limit(limit).offset(offset)
|
||||
|
||||
serialized_domains = @domains.map do |item|
|
||||
serializer = Serializers::RegistrantApi::Domain.new(item)
|
||||
domains = current_user_domains
|
||||
serialized_domains = domains.limit(limit).offset(offset).map do |item|
|
||||
serializer = Serializers::RegistrantApi::Domain.new(item, simplify: simple)
|
||||
serializer.to_json
|
||||
end
|
||||
|
||||
render json: serialized_domains
|
||||
render json: { count: domains.count, domains: serialized_domains }
|
||||
end
|
||||
|
||||
def show
|
||||
@domain = current_user_domains.find_by(uuid: params[:uuid])
|
||||
|
||||
if @domain
|
||||
serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
||||
serializer = Serializers::RegistrantApi::Domain.new(@domain, simplify: false)
|
||||
render json: serializer.to_json
|
||||
else
|
||||
render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found
|
||||
|
|
|
@ -347,19 +347,24 @@ class Contact < ApplicationRecord
|
|||
@desc = {}
|
||||
|
||||
registrant_domains.each do |dom|
|
||||
@desc[dom.name] ||= []
|
||||
@desc[dom.name] << :registrant
|
||||
@desc[dom.name] ||= { id: dom.uuid, roles: [] }
|
||||
@desc[dom.name][:roles] << :registrant
|
||||
end
|
||||
|
||||
domain_contacts.each do |dc|
|
||||
@desc[dc.domain.name] ||= []
|
||||
@desc[dc.domain.name] << dc.name.downcase.to_sym
|
||||
@desc[dc.domain.name] ||= { id: dc.domain.uuid, roles: [] }
|
||||
@desc[dc.domain.name][:roles] << dc.name.downcase.to_sym
|
||||
@desc[dc.domain.name] = @desc[dc.domain.name].compact
|
||||
end
|
||||
|
||||
@desc
|
||||
end
|
||||
|
||||
def related_domains
|
||||
a = related_domain_descriptions
|
||||
a.keys.map { |d| { name: d, id: a[d][:id], roles: a[d][:roles] } }
|
||||
end
|
||||
|
||||
def status_notes_array=(notes)
|
||||
self.status_notes = {}
|
||||
notes ||= []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue