mirror of
https://github.com/internetee/registry.git
synced 2025-08-19 07:53:51 +02:00
Merge 9cdd86a5d5
into c8a0788366
This commit is contained in:
commit
5cd96e17e1
2 changed files with 11 additions and 8 deletions
|
@ -7,13 +7,14 @@ module Api
|
||||||
before_action :set_tech_flag, only: [:show]
|
before_action :set_tech_flag, only: [:show]
|
||||||
|
|
||||||
LIMIT_DOMAIN_TOTAL = 3000
|
LIMIT_DOMAIN_TOTAL = 3000
|
||||||
|
LIMIT_PARTIAL = 100
|
||||||
|
|
||||||
def index
|
def index
|
||||||
limit = params[:limit] || 200
|
limit = params[:limit] || LIMIT_PARTIAL
|
||||||
offset = params[:offset] || 0
|
offset = params[:offset] || 0
|
||||||
simple = params[:simple] == 'true' || false
|
simple = params[:simple] == 'true' || false
|
||||||
|
|
||||||
if limit.to_i > 200 || limit.to_i < 1
|
if limit.to_i > LIMIT_PARTIAL || limit.to_i < 1
|
||||||
render(json: { errors: [{ limit: ['parameter is out of range'] }] },
|
render(json: { errors: [{ limit: ['parameter is out of range'] }] },
|
||||||
status: :bad_request) && return
|
status: :bad_request) && return
|
||||||
end
|
end
|
||||||
|
@ -24,13 +25,15 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
domains = current_user_domains
|
domains = current_user_domains
|
||||||
serialized_domains = domains.limit(limit).offset(offset).map do |item|
|
@domains = Rails.cache.fetch(domains) do
|
||||||
serializer = Serializers::RegistrantApi::Domain.new(item, simplify: simple)
|
domains.limit(limit).offset(offset).map do |item|
|
||||||
serializer.to_json
|
serializer = Serializers::RegistrantApi::Domain.new(item, simplify: simple)
|
||||||
|
serializer.to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { total: current_user_domains_total_count, count: domains.count,
|
render json: { total: current_user_domains_total_count, count: domains.count,
|
||||||
domains: serialized_domains }
|
domains: @domains }
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -111,7 +111,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
||||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_equal(200, response.status)
|
assert_equal(200, response.status)
|
||||||
assert_equal(2, response_json[:domains].count)
|
assert_equal(4, response_json[:domains].count)
|
||||||
|
|
||||||
get '/api/v1/registrant/domains', headers: @auth_headers
|
get '/api/v1/registrant/domains', headers: @auth_headers
|
||||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
@ -129,7 +129,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_root_does_not_accept_offset_lower_than_0
|
def test_root_does_not_accept_offset_lower_than_0
|
||||||
get '/api/v1/registrant/domains', params: { 'limit' => 200, 'offset' => "-10" },
|
get '/api/v1/registrant/domains', params: { 'limit' => 100, 'offset' => "-10" },
|
||||||
headers: @auth_headers
|
headers: @auth_headers
|
||||||
|
|
||||||
assert_equal(400, response.status)
|
assert_equal(400, response.status)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue