 
 (defn send-past-positions [channel params]
   "send all past positions to websocket channel"
-  (def positions (redis/wcar* (car/lrange (get-position-key params) 0 -1)))
+  (def positions (position/fetch-positions params))
   (doseq [p (reverse positions)] (send-position channel p)))
 
 (defn subscribe-to-redis [channel trip-id]

    (subscribe-to-redis channel (:id params))
    (send-past-positions channel params)))

(defn update [req] 
  "update position for trip"
  (def params (:params req))
  (redis/wcar* 
    (if (car/get (:id params)) 
      (do
        (car/publish (:id params) (map params [:lat :lon :instant]))
        (car/lpush (get-position-key params) (select-keys params [:lat :lon :instant])))
      "BORK!(trip not found)"))
  "Position updated.")

    [snap-spot.redis :as redis]
    [taoensso.carmine :as car :refer (wcar)]
    [taoensso.timbre :as timbre]
    [bouncer.core :as b]
    [bouncer.validators :as v]
    [clojure.data.json :as json]
    [me.shenfeng.mustache :as mustache]
    [snap-spot.helper :as helper]
    [snap-spot.models 
     (position :as position)
     (trip :as trip)]))

(timbre/refer-timbre)


(defn send-position [channel position]
  "send postion to websocket channel"
