Skip to content

Commit

Permalink
Working program endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
achan authored and achan committed Dec 30, 2024
1 parent 92daaa5 commit c8053b2
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,31 @@ def location
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
# Start with filtering by institution programs based on description
institution_programs = InstitutionProgram.joins(:institution)
.where('institution_programs.description ILIKE ?', "%#{@query[:description]}%")
.where(institutions: { version: @version })

# Now filter by location
location_results = Institution.approved_institutions(@version)
.location_search(@query)
.filter_result_v1(@query)
.where(id: institution_programs.select(:institution_id))

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

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

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


# GET /v1/institutions?facility_codes=1,2,3,4
# Search by facility code and return using InstitutionCompareSerializer
def facility_codes
Expand Down

0 comments on commit c8053b2

Please sign in to comment.