From 2ff955ddd3d7fe703e35ed21cbf1bd82d5f51dd6 Mon Sep 17 00:00:00 2001 From: Jacob Rockwell Date: Mon, 26 Apr 2021 17:28:43 -0700 Subject: [PATCH 1/5] Implemented organizations API for HSDS compliance --- app/controllers/organizations_controller.rb | 31 ++++++ app/presenters/organizations_presenter.rb | 12 +++ config/routes.rb | 8 +- swagger/v1/swagger.json | 104 ++++++++++++++++++++ 4 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 app/controllers/organizations_controller.rb create mode 100644 app/presenters/organizations_presenter.rb diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 00000000..f9024d00 --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,31 @@ +class OrganizationsController < ApplicationController + '''Organizations Controller. Key names changed to be HSDS compliant''' + def index + organization = Resource.order(:name) + # push elements into list to meet formatting requirements for HSDS + organization_container = [] + organization.each do |element| + organization_container.push(element) + end + render json: OrganizationsPresenter.present(organization_container) + end + def show + # Find the relevant resource and adjust variables for HSDS form + resource = Resource.find([params[:id]]) + + render json: OrganizationsPresenter.present(resource) + end + + def destroy + org = Resource.find params[:id] + org.delete + end + + def organization + # Note: We *must* use #preload instead of #includes to force Rails to make a + # separate query per table. Otherwise, it creates one large query with many + # joins, which amplifies the amount of data being sent between Rails and the + # DB by several orders of magnitude due to duplication of tuples. + Resource.preload(:resources) + end +end diff --git a/app/presenters/organizations_presenter.rb b/app/presenters/organizations_presenter.rb new file mode 100644 index 00000000..32bfdf82 --- /dev/null +++ b/app/presenters/organizations_presenter.rb @@ -0,0 +1,12 @@ +class OrganizationsPresenter < Jsonite + property :id + property :name + property :alternate_name + property(:description) { long_description } + property :email + property(:url) { website } + property(:tax_status){ nil } + property(:tax_id){ nil } + property(:year_incorporated){ nil } + property :legal_status +end diff --git a/config/routes.rb b/config/routes.rb index af22cd2d..6871e832 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,6 @@ get :counts get :featured get :subcategories - get :hierarchy end end resources :eligibilities, only: %i[index show update] do @@ -26,14 +25,14 @@ post :create post :certify + resources :ratings, only: :create resources :change_requests, only: :create resources :services, only: :create - resources :feedbacks, only: %i[create index] end resources :services do + resources :ratings, only: :create resources :change_requests, only: :create resources :notes, only: :create - resources :feedbacks, only: %i[create index] post :approve post :reject post :certify @@ -46,6 +45,9 @@ resources :notes do resources :change_requests, only: :create end + resources :organizations do + resources :change_requests, only: :create + end resources :addresses do resources :change_requests, only: :create end diff --git a/swagger/v1/swagger.json b/swagger/v1/swagger.json index e0ab1be2..9479ce11 100644 --- a/swagger/v1/swagger.json +++ b/swagger/v1/swagger.json @@ -1590,6 +1590,110 @@ "application/json" ] } + }, + + "/phones/{id}": { + "get": { + "responses": { + "200": { + "examples": { + "application/json": { + "id": "string", + "number": "string", + "extension": "string", + "service_type": "string", + "country_code": "string" + } + }, + "description": "Phone Response" + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "type": "integer", + "description": "Phone ID", + "required": true + } + ], + "tags": [ + "phones" + ], + "summary": "Retrieves phone numbers by id", + "produces" : [ + "application/json" + ] + } + }, + "/organizations": { + "get": { + "responses": { + "200": { + "examples": { + "application/json": { + "id": "string", + "name": "string", + "alternate_name": "string", + "description": "string", + "email": "string", + "url": "string", + "tax_status": "string", + "tax_id": "string", + "year_incorporated": "string", + "legal_status": "string" + } + }, + "description": "Organization Response" + } + }, + "tags": [ + "organizations" + ], + "summary": "Retrieves all organizations", + "produces" : [ + "application/json" + ] + } + }, + "/organizations/{id}": { + "get": { + "responses": { + "200": { + "examples": { + "application/json": { + "id": "string", + "name": "string", + "alternate_name": "string", + "description": "string", + "email": "string", + "url": "string", + "tax_status": "string", + "tax_id": "string", + "year_incorporated": "string", + "legal_status": "string" + } + }, + "description": "Organization Response" + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "type": "integer", + "description": "Resource ID", + "required": true + } + ], + "tags": [ + "organizations" + ], + "summary": "Retrieves organization by id", + "produces" : [ + "application/json" + ] + } } } } From 2dcadb61b77a2eae15b659d779a930860134269d Mon Sep 17 00:00:00 2001 From: Jacob Rockwell Date: Mon, 26 Apr 2021 17:43:14 -0700 Subject: [PATCH 2/5] merging config/routes.rb with more recent version --- config/routes.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6871e832..85ae0254 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ get :counts get :featured get :subcategories + get :hierarchy end end resources :eligibilities, only: %i[index show update] do @@ -25,14 +26,14 @@ post :create post :certify - resources :ratings, only: :create resources :change_requests, only: :create resources :services, only: :create + resources :feebacks, only: %i[create index] end resources :services do - resources :ratings, only: :create resources :change_requests, only: :create resources :notes, only: :create + resources :feedbacks, only: %i[create index] post :approve post :reject post :certify From 9cbfc5543b47899ecdd1c8ae04417c9c4c51e3a0 Mon Sep 17 00:00:00 2001 From: Jacob Rockwell Date: Mon, 26 Apr 2021 17:44:12 -0700 Subject: [PATCH 3/5] merging config/routes.rb after mistake --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 85ae0254..6e1176be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,7 @@ resources :services do resources :change_requests, only: :create resources :notes, only: :create - resources :feedbacks, only: %i[create index] + resources :feedback, only: %i[create index] post :approve post :reject post :certify From 456d36b1ab9b2bcab00eaa54a7b353fd4388bd99 Mon Sep 17 00:00:00 2001 From: Jacob Rockwell Date: Mon, 26 Apr 2021 17:45:10 -0700 Subject: [PATCH 4/5] merging config/routes.rb after final mistake --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6e1176be..cdb5c555 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,12 +28,12 @@ resources :change_requests, only: :create resources :services, only: :create - resources :feebacks, only: %i[create index] + resources :feedbacks, only: %i[create index] end resources :services do resources :change_requests, only: :create resources :notes, only: :create - resources :feedback, only: %i[create index] + resources :feedbacks, only: %i[create index] post :approve post :reject post :certify From dfd20e679c79b4efa316a35bc0702a3469783d13 Mon Sep 17 00:00:00 2001 From: Jacob Rockwell Date: Mon, 26 Apr 2021 17:48:42 -0700 Subject: [PATCH 5/5] updated api-docs --- swagger/v1/swagger.json | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/swagger/v1/swagger.json b/swagger/v1/swagger.json index 9479ce11..128764b0 100644 --- a/swagger/v1/swagger.json +++ b/swagger/v1/swagger.json @@ -1591,41 +1591,6 @@ ] } }, - - "/phones/{id}": { - "get": { - "responses": { - "200": { - "examples": { - "application/json": { - "id": "string", - "number": "string", - "extension": "string", - "service_type": "string", - "country_code": "string" - } - }, - "description": "Phone Response" - } - }, - "parameters": [ - { - "name": "id", - "in": "path", - "type": "integer", - "description": "Phone ID", - "required": true - } - ], - "tags": [ - "phones" - ], - "summary": "Retrieves phone numbers by id", - "produces" : [ - "application/json" - ] - } - }, "/organizations": { "get": { "responses": {