File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020
2121; ; Our database with stops, routes, directions
2222
23- (defonce ttc (nextbus/load-agency " ttc " ))
23+ (defonce ttc (ref nil ))
2424
2525; ; Helpers to parse request parameters
2626
4343 (handler
4444 (update-in req [:uri ] #(if (= " /" %) " /index.html" %)))))
4545
46+ ; ;
47+
48+ (defn init []
49+ (dosync
50+ (ref-set ttc (nextbus/load-agency " ttc" ))))
51+
4652; ; The routes and app handler
4753
4854(defroutes api-routes
5561 :used (- (.totalMemory rt) (.freeMemory rt))}})))
5662 (GET " /api/stops" {params :params }
5763 (let [position (position-from-params params) radius (radius-from-params params)]
58- (response {:stops (nextbus/find-stops ttc position radius)
64+ (response {:stops (nextbus/find-stops @ ttc position radius)
5965 :position position})))
6066 (GET " /api/predictions-for-position" {params :params }
6167 (let [position (position-from-params params) radius (radius-from-params params)]
62- (response {:predictions (nextbus/predictions ttc (nextbus/find-stops ttc position radius))
68+ (response {:predictions (nextbus/predictions @ ttc (nextbus/find-stops @ ttc position radius))
6369 :position position})))
6470 (GET " /api/predictions-for-stops" {params :params }
6571 (let [stops (stops-from-params params)]
6672 (prn stops)
67- (response {:predictions (nextbus/predictions ttc stops)
73+ (response {:predictions (nextbus/predictions @ ttc stops)
6874 :stops stops})))
6975 (route/resources " /" )
7076 (route/not-found " Not found" ))
You can’t perform that action at this time.
0 commit comments