Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

513 Implemented a HSDS compliant organization API #579

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions app/presenters/organizations_presenter.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions swagger/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
}
}