mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 16:02:03 +02:00
Add handling of type filters and handling of ETags
Add API documentation and test cases around ETags for the API.
This commit is contained in:
parent
960e4084e3
commit
6e5a97ad4d
5 changed files with 182 additions and 19 deletions
|
@ -2,10 +2,14 @@ module Repp
|
|||
module V1
|
||||
class RetainedDomainsController < ActionController::API
|
||||
def index
|
||||
domains = RetainedDomains.new
|
||||
domains = RetainedDomains.new(query_params)
|
||||
|
||||
render json: { count: domains.count, domains: domains.to_jsonable }
|
||||
end
|
||||
|
||||
def query_params
|
||||
params.permit(:type)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,26 +4,55 @@ class RetainedDomains
|
|||
RESERVED = 'reserved'.freeze
|
||||
BLOCKED = 'blocked'.freeze
|
||||
|
||||
attr_reader :domains
|
||||
attr_reader :domains,
|
||||
:type
|
||||
|
||||
def initialize
|
||||
def initialize(params)
|
||||
@type = establish_type(params)
|
||||
@domains = gather_domains
|
||||
end
|
||||
|
||||
def gather_domains
|
||||
blocked_domains = BlockedDomain.order(name: :desc).all
|
||||
reserved_domains = ReservedDomain.order(name: :desc).all
|
||||
delegate :count, to: :domains
|
||||
|
||||
def to_jsonable
|
||||
domains.map { |el| domain_to_jsonable(el) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def establish_type(params)
|
||||
type = params[:type]
|
||||
|
||||
case type
|
||||
when 'reserved' then :reserved
|
||||
when 'blocked' then :blocked
|
||||
else :all
|
||||
end
|
||||
end
|
||||
|
||||
def gather_domains
|
||||
domains = blocked_domains.to_a.union(reserved_domains.to_a)
|
||||
|
||||
domains.sort_by(&:name)
|
||||
end
|
||||
|
||||
def to_jsonable
|
||||
domains.map { |el| domain_to_json(el) }
|
||||
def blocked_domains
|
||||
if %i[all blocked].include?(type)
|
||||
BlockedDomain.order(name: :desc).all
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def domain_to_json(domain)
|
||||
def reserved_domains
|
||||
if %i[all reserved].include?(type)
|
||||
ReservedDomain.order(name: :desc).all
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def domain_to_jsonable(domain)
|
||||
status = case domain
|
||||
when ReservedDomain then RESERVED
|
||||
when BlockedDomain then BLOCKED
|
||||
|
@ -37,6 +66,4 @@ class RetainedDomains
|
|||
punycode_name: punycode,
|
||||
}
|
||||
end
|
||||
|
||||
delegate :count, to: :domains
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue