Update domains controller to return serialized domains now

This commit is contained in:
Maciej Szlosarczyk 2018-10-02 11:36:44 +03:00
parent ed0316dd83
commit ce8451d004
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
3 changed files with 73 additions and 33 deletions

View file

@ -1,3 +1,5 @@
require 'serializers/registrant_api/domain'
module Api module Api
module V1 module V1
module Registrant module Registrant
@ -17,7 +19,13 @@ module Api
end end
@domains = associated_domains(current_registrant_user).limit(limit).offset(offset) @domains = associated_domains(current_registrant_user).limit(limit).offset(offset)
render json: @domains
serialized_domains = @domains.map do |item|
serializer = Serializers::RegistrantApi::Domain.new(item)
serializer.to_json
end
render json: serialized_domains
end end
def show def show
@ -25,7 +33,8 @@ module Api
@domain = domain_pool.find_by(uuid: params[:uuid]) @domain = domain_pool.find_by(uuid: params[:uuid])
if @domain if @domain
render json: @domain serializer = Serializers::RegistrantApi::Domain.new(@domain)
render json: serializer.to_json
else else
render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found
end end

View file

@ -11,15 +11,6 @@ Returns domains of the current registrant.
| ---------- | -------- | ---- | -------------- | ----------- | | ---------- | -------- | ---- | -------------- | ----------- |
| limit | false | Integer | [1..200] | How many domains to show | | limit | false | Integer | [1..200] | How many domains to show |
| offset | false | Integer | | Domain number to start at | | offset | false | Integer | | Domain number to start at |
| details | false | String | ["true", "false"] | Whether to include details |
#### Request
```
GET api/v1/registrant/domains?limit=1&details=true HTTP/1.1
Accept: application/json
Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Type: application/json
```
#### Response #### Response
``` ```
@ -27,13 +18,11 @@ HTTP/1.1 200
Content-Type: application/json Content-Type: application/json
{ {
"domains": [ [
{ {
"uuid": "98d1083a-8863-4153-93e4-caee4a013535", "id": "98d1083a-8863-4153-93e4-caee4a013535",
"name": "domain0.ee", "name": "domain0.ee",
"registrar_id": 2, "registrar": "Best Names",
"registered_at": "2015-09-09T09:11:14.861Z",
"status": null,
"valid_from": "2015-09-09T09:11:14.861Z", "valid_from": "2015-09-09T09:11:14.861Z",
"valid_to": "2016-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z",
"registrant_id": 1, "registrant_id": 1,
@ -53,23 +42,28 @@ Content-Type: application/json
"delete_at": "2016-10-24T09:11:14.861Z", "delete_at": "2016-10-24T09:11:14.861Z",
"registrant_verification_asked_at": null, "registrant_verification_asked_at": null,
"registrant_verification_token": null, "registrant_verification_token": null,
"pending_json": { "locked_by_registrant_at": "2015-09-09T09:11:14.861Z",
}, "pending_json": {},
"force_delete_at": null, "force_delete_at": null,
"statuses": [ "statuses": [
"ok" "ok"
], ],
"reserved": false, "reserved": false,
"status_notes": { "status_notes": {},
}, "statuses_backup": []
"statuses_backup": [
]
} }
], ]
"total_number_of_records": 2
} }
``` ```
#### Request
```
GET api/v1/registrant/domains HTTP/1.1
Accept: application/json
Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Type: application/json
```
## GET api/v1/registrant/domains ## GET api/v1/registrant/domains
Returns domain names with offset. Returns domain names with offset.
@ -77,7 +71,7 @@ Returns domain names with offset.
#### Request #### Request
``` ```
GET api/v1/registrant/domains?offset=1 HTTP/1.1 GET api/v1/registrant/domains?offset=1&limit=1 HTTP/1.1
Accept: application/json Accept: application/json
Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Type: application/json Content-Type: application/json
@ -89,10 +83,40 @@ HTTP/1.1 200
Content-Type: application/json Content-Type: application/json
{ {
"domains": [ [
"domain1.ee" {
], "id": "98d1083a-8863-4153-93e4-caee4a013535",
"total_number_of_records": 2 "name": "domain0.ee",
"registrar": "Best Names",
"valid_to": "2016-09-09T09:11:14.861Z",
"registrant_id": 1,
"transfer_code": "98oiewslkfkd",
"created_at": "2015-09-09T09:11:14.861Z",
"updated_at": "2015-09-09T09:11:14.860Z",
"name_dirty": "domain0.ee",
"name_puny": "domain0.ee",
"period": 1,
"period_unit": "y",
"creator_str": null,
"updator_str": null,
"legacy_id": null,
"legacy_registrar_id": null,
"legacy_registrant_id": null,
"outzone_at": "2016-09-24T09:11:14.861Z",
"delete_at": "2016-10-24T09:11:14.861Z",
"registrant_verification_asked_at": null,
"registrant_verification_token": null,
"locked_by_registrant_at": "2015-09-09T09:11:14.861Z",
"pending_json": {},
"force_delete_at": null,
"statuses": [
"ok"
],
"reserved": false,
"status_notes": {},
"statuses_backup": []
}
]
} }
``` ```
@ -116,12 +140,10 @@ HTTP/1.1 200
Content-Type: application/json Content-Type: application/json
{ {
"uuid": "98d1083a-8863-4153-93e4-caee4a013535", "id": "98d1083a-8863-4153-93e4-caee4a013535",
"name": "domain0.ee", "name": "domain0.ee",
"registrar_id": 2, "registrar": "Best Names",
"registered_at": "2015-09-09T09:11:14.861Z", "registered_at": "2015-09-09T09:11:14.861Z",
"status": null,
"valid_from": "2015-09-09T09:11:14.861Z",
"valid_to": "2016-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z",
"registrant_id": 1, "registrant_id": 1,
"transfer_code": "98oiewslkfkd", "transfer_code": "98oiewslkfkd",
@ -140,6 +162,7 @@ Content-Type: application/json
"delete_at": "2016-10-24T09:11:14.861Z", "delete_at": "2016-10-24T09:11:14.861Z",
"registrant_verification_asked_at": null, "registrant_verification_asked_at": null,
"registrant_verification_token": null, "registrant_verification_token": null,
"locked_by_registrant_at": "2015-09-09T09:11:14.861Z",
"pending_json": {}, "pending_json": {},
"force_delete_at": null, "force_delete_at": null,
"statuses": [ "statuses": [

View file

@ -27,7 +27,12 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
assert_equal(200, response.status) assert_equal(200, response.status)
domain = JSON.parse(response.body, symbolize_names: true) domain = JSON.parse(response.body, symbolize_names: true)
assert_equal('hospital.test', domain[:name]) assert_equal('hospital.test', domain[:name])
assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id])
assert_equal('Good Names', domain[:registrar])
assert_equal([], domain[:nameservers])
assert(domain.has_key?(:locked_by_registrant_at))
end end
def test_get_non_existent_domain_details_by_uuid def test_get_non_existent_domain_details_by_uuid
@ -45,6 +50,9 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
response_json = JSON.parse(response.body, symbolize_names: true) response_json = JSON.parse(response.body, symbolize_names: true)
array_of_domain_names = response_json.map { |x| x[:name] } array_of_domain_names = response_json.map { |x| x[:name] }
assert(array_of_domain_names.include?('hospital.test')) assert(array_of_domain_names.include?('hospital.test'))
array_of_domain_registrars = response_json.map { |x| x[:registrar] }
assert(array_of_domain_registrars.include?('Good Names'))
end end
def test_root_accepts_limit_and_offset_parameters def test_root_accepts_limit_and_offset_parameters