mirror of
https://github.com/internetee/registry.git
synced 2025-08-18 23:43:57 +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]
|
||||
|
||||
LIMIT_DOMAIN_TOTAL = 3000
|
||||
LIMIT_PARTIAL = 100
|
||||
|
||||
def index
|
||||
limit = params[:limit] || 200
|
||||
limit = params[:limit] || LIMIT_PARTIAL
|
||||
offset = params[:offset] || 0
|
||||
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'] }] },
|
||||
status: :bad_request) && return
|
||||
end
|
||||
|
@ -24,13 +25,15 @@ module Api
|
|||
end
|
||||
|
||||
domains = current_user_domains
|
||||
serialized_domains = domains.limit(limit).offset(offset).map do |item|
|
||||
@domains = Rails.cache.fetch(domains) do
|
||||
domains.limit(limit).offset(offset).map do |item|
|
||||
serializer = Serializers::RegistrantApi::Domain.new(item, simplify: simple)
|
||||
serializer.to_json
|
||||
end
|
||||
end
|
||||
|
||||
render json: { total: current_user_domains_total_count, count: domains.count,
|
||||
domains: serialized_domains }
|
||||
domains: @domains }
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -111,7 +111,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
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
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -129,7 +129,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
assert_equal(400, response.status)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue