app/helpers/courses_helpers.rb
# gets a single course or an array or courses and halts if none are found
# @return: Array of courses
gets a single course or an array or courses and halts if none are found
gets a single course or an array or courses and halts if none are found
def find_courses db, semester, course_ids, params
        course_ids = [course_ids] if course_ids.is_a?(String)
        validate_course_ids course_ids
        courses_ids_string = (course_ids.map {|e| "'#{e}'"}).join ','
        res = db.exec("SELECT * FROM courses WHERE semester=#{semester} AND course_id in (#{courses_ids_string})")
        courses = []
        res.each do |row|
          courses << (clean_course db, semester, row)
        end
        if courses.empty?
          s = course_ids.length > 1 ? 's' : ''
          halt 404, {
            error_code: 404,
            message: "Course#{s} with course_id#{s} #{course_ids.join(',')} not found!",
            available_courses: "https://api.umd.io/v0/courses",
            docs: "https://umd.io/courses/"
          }.to_json
        end
        courses
      end
def find_courses db , semester , course_ids , params course_ids = [ course_ids ] if course_ids . is_a? ( String ) validate_course_ids course_ids courses_ids_string = ( course_ids . map { | e | "'#{e}'" } ) . join ',' res = db . exec ( "SELECT * FROM courses WHERE semester=#{semester} AND course_id in (#{courses_ids_string})" ) courses = [ ] res . each do | row | courses << ( clean_course db , semester , row ) end if courses . empty? s = course_ids . length > 1 ? 's' : '' halt 404 , { error_code : 404 , message : "Course#{s} with course_id#{s} #{course_ids.join(',')} not found!" , available_courses : "https://api.umd.io/v0/courses" , docs : "https://umd.io/courses/" } . to_json end courses end
gets a single course or an array or courses and halts if none are found
gets a single course or an array or courses and halts if none are found
# Turn course_ids into string # This is proably ok, because we know that semester and sectcourse_idsion_ids both match expected formats # TODO: Take another look here, for security purposes # check if found
db
semester
course_ids
params
return:
Array of courses
Array of courses