Last active
June 29, 2021 21:28
-
-
Save oafridi/17255209748455bdfa877f373e83ad3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Params: state, id, limit, offset | |
class Api::NearbySchoolsController < ApplicationController | |
before_filter :require_school | |
def show | |
get_array_of_nearby_school_hashes() | |
end | |
def limit | |
return 3 unless params[:limit] | |
[params[:limit].to_i, 6].min | |
end | |
def school | |
# find_by_state_and_id method might return nil | |
@school ||= School.find_by_state_and_id(params[:state].downcase!, params[:id]) | |
end | |
def require_school | |
if school.blank? | |
if !school.active? | |
render json: {error: 'School not found'}, status: 404 | |
end | |
end | |
end | |
def get_array_of_nearby_school_hashes | |
array_of_nearby_school_hashes = NearbySchoolsService.nearby_schools( | |
school, | |
limit: limit, | |
offset: params[:offset].to_i | |
) | |
@array_of_nearby_school_hashes = array_of_nearby_school_hashes | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment