diff --git a/FireResponse/app/controllers/tables_controller.rb b/FireResponse/app/controllers/tables_controller.rb index 57c5b0d..da01b27 100644 --- a/FireResponse/app/controllers/tables_controller.rb +++ b/FireResponse/app/controllers/tables_controller.rb @@ -1,29 +1,10 @@ class TablesController < ApplicationController - def recent_news - render json: RecentNews.all.to_json - end - def resources - render json: Resources.all.to_json - end - - def support_services - render json: SupportServices.all.to_json - end - - def gas_stations - render json: GasStations.all.to_json - end - - def markets - render json: Markets.all.to_json - end - - def shelters - render json: Shelters.all.to_json - end - - def volunteering - render json: Volunteering.all.to_json + AirtableSheets.each do |k,v| + define_method(k) do + ::Rails.cache.fetch("cache/#{k}", expires_in: 30.seconds) do + render json: v.all.to_json + end + end end end diff --git a/FireResponse/config/initializers/airtable.rb b/FireResponse/config/initializers/airtable.rb index bcd2aaa..4ebd7e3 100644 --- a/FireResponse/config/initializers/airtable.rb +++ b/FireResponse/config/initializers/airtable.rb @@ -1 +1,11 @@ Airrecord.api_key = ENV['AIRTABLE_BASE'] + +AirtableSheets = { + recent_news: RecentNews, + resources: Resources, + support_services: SupportServices, + gas_stations: GasStations, + markets: Markets, + shelters: Shelters, + volunteering: Volunteering, + } diff --git a/FireResponse/config/routes.rb b/FireResponse/config/routes.rb index c4bb01a..ffeb2b4 100644 --- a/FireResponse/config/routes.rb +++ b/FireResponse/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - ['recent_news', 'resources', 'support_services', 'gas_stations', 'markets', 'shelters', 'volunteering'].each do |x| + AirtableSheets.keys.each do |x| get "/#{x}", to: "tables##{x}" end end