Skip to content

Commit

Permalink
Add program search to gids
Browse files Browse the repository at this point in the history
  • Loading branch information
achan authored and achan committed Dec 29, 2024
1 parent 6f29037 commit 92daaa5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ def location
meta: @meta
end

# GET /v1/institutions?description=nursing&latitude=42.3601&longitude=-71.0589
def program
@query ||= normalized_query_params

# First find matching programs
matching_programs = InstitutionProgram
.joins(institution: :version)
.where(institutions: { version: @version })
.where('LOWER(description) LIKE ?', "%#{@query[:description].downcase}%")
.select('DISTINCT ON (institutions.id) institutions.id')

# Apply location search if coordinates provided
results = Institution.approved_institutions(@version).where(id: matching_programs)

if @query[:latitude].present? && @query[:longitudse].present?
results = results.location_search(@query).location_select(@query).location_order
end

results = results.filter_high_school if @query[:excluded_school_types]&.include?('HIGH SCHOOL')

@meta = {
version: @version,
count: results.count,
facets: facets(results)
}
@links = { self: self_link }

render json: results,
each_serializer: InstitutionProfileSerializer,
meta: @meta,
links: @links
end


# GET /v1/institutions?facility_codes=1,2,3,4
# Search by facility code and return using InstitutionCompareSerializer
def facility_codes
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
namespace :v1, defaults: { format: 'json' } do
get '/calculator/constants' => 'calculator_constants#index'
get '/institutions', to: 'institutions#facility_codes', constraints: lambda { |request| request.query_parameters.key?(:facility_codes) }
get '/institutions', to: 'institutions#program', constraints: lambda { |request|
request.query_parameters.key?(:description) &&
request.query_parameters.key?(:latitude) &&
request.query_parameters.key?(:longitude)
}
get '/institutions', to: 'institutions#location', constraints: lambda { |request| request.query_parameters.key?(:latitude) && request.query_parameters.key?(:longitude) }

resources :institutions, only: [:index, :show] do
Expand Down

0 comments on commit 92daaa5

Please sign in to comment.