app/helpers/courses_helpers.rb
def check_semester app, semester, table
        # check for semester formatting
        if not (semester.length == 6 and semester.is_number?)
          halt 400, { error_code: 400, message: "Invalid semester parameter! semester must be 6 digits" }.to_json
        end

        # check if table exists
        begin
          app.settings.postgres.exec("SELECT * from #{table} WHERE semester=#{semester} LIMIT 1")
        rescue PG::UndefinedTable
          msg = "We don't have data for this semester! If you leave off the semester parameter, we'll give you the courses currently on Testudo"
          halt 404, {error_code: 404, message: msg}.to_json
        end

        true
      end
# generalize logic for checking if semester param valid
generalize logic for checking if semester param valid
generalize logic for checking if semester param valid
def check_semester app, semester, table
        if not (semester.length == 6 and semester.is_number?)
          halt 400, { error_code: 400, message: "Invalid semester parameter! semester must be 6 digits" }.to_json
        end
        begin
          app.settings.postgres.exec("SELECT * from #{table} WHERE semester=#{semester} LIMIT 1")
        rescue PG::UndefinedTable
          msg = "We don't have data for this semester! If you leave off the semester parameter, we'll give you the courses currently on Testudo"
          halt 404, {error_code: 404, message: msg}.to_json
        end
        true
      end
def check_semester app , semester , table if not ( semester . length == 6 and semester . is_number? ) halt 400 , { error_code : 400 , message : "Invalid semester parameter! semester must be 6 digits" } . to_json end begin app . settings . postgres . exec ( "SELECT * from #{table} WHERE semester=#{semester} LIMIT 1" ) rescue PG :: UndefinedTable msg = "We don't have data for this semester! If you leave off the semester parameter, we'll give you the courses currently on Testudo" halt 404 , { error_code : 404 , message : msg } . to_json end true end
generalize logic for checking if semester param valid
generalize logic for checking if semester param valid
# check for semester formatting # check if table exists
app
semester
table