                   (clojure.set/rename-keys {:id :channel-id})))))
 
   (korma/defentity threads
-    (korma/table :threads)
     (korma/transform
       (fn [t] (clojure.set/rename-keys t {:id :thread-id
                                           :channel_id :channel-id}))))
 
   (korma/defentity messages
-    (korma/table :messages)
     (korma/transform
       (fn [m] (-> m
                   (clojure.set/rename-keys {:id :message-id

          channel-id (Integer/parseInt (:channel-id params))
          thread-id (Integer/parseInt (:thread-id params))]
      (get-messages channel-id thread-id))))

(defn add-msg [channel-id thread-id msg]
  (korma/insert messages
    (korma/values {:channel_id channel-id
                   :thread_id thread-id
                   :message msg})))

(defn chat-thread-ws-handler [ch request]
  (let [params (:route-params request)

          lat (Double/parseDouble (:lat params))]
      (get-channels lon lat))))

(defn new-channel-handler [request]
  (edn-response
    (let [body (read-string (slurp (:body request)))
          geolocation (:geolocation body)]
      (add-channel (:channel-name body) (:lon geolocation) (:lat geolocation)))))

(defn chat-threads-handler [request]
  (edn-response
