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..cdb5c555 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,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..128764b0 100644 --- a/swagger/v1/swagger.json +++ b/swagger/v1/swagger.json @@ -1590,6 +1590,75 @@ "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" + ] + } } } }