 (defn http-put-store [mqtt context]
   (if-let [d (storemodel/update (get-in context [:path-params :id]) (:json-params context))]
     (do (mqttapi/publish-scmessage mqtt "/config/update"
-                                (scm/map->SCMessage
-                                  {:action (.value SCCommand/CONFIG_UPDATE_STORE)
-                                   :payload d}))
-     (response/ok "success"))
+                                   (scm/map->SCMessage
+                                    {:action (.value SCCommand/CONFIG_UPDATE_STORE)
+                                     :payload d}))
+        (response/ok "success"))
     (response/error "Error updating")))
 
 (defn http-post-store [mqtt context]
   (if-let [d (storemodel/create (:json-params context))]
     (do (mqttapi/publish-scmessage mqtt "/config/update"
-                                (scm/map->SCMessage {:action (.value SCCommand/CONFIG_ADD_STORE)
-                                                     :payload d}))
-     (response/ok d))
+                                   (scm/map->SCMessage {:action (.value SCCommand/CONFIG_ADD_STORE)
+                                                        :payload d}))
+        (response/ok d))
     (response/error "Error creating")))
 
 (defn http-delete-store [mqtt context]

                       ["/api/stores" :post
                        (conj intercept/common-interceptors (partial http-post-store mqtt)) :route-name :http-post-store]
                       ["/api/stores/:id" :delete
                        (conj intercept/common-interceptors (partial http-delete-store mqtt)) :route-name :http-delete-store]})

(defrecord StoreComponent [mqtt trigger]
  component/Lifecycle

(defn load-polling-stores []
  (doall (map add-polling-store (storemodel/all))))

(defn get-capabilities->layer-names [caps]
  (let [layer-names (->> caps
                         .getBytes
                         java.io.ByteArrayInputStream.
                         xml/parse
                         :content
                         (filter #(= :FeatureTypeList (:tag %)))
                         first
                         :content
                         (filter #(= :FeatureType (:tag %)))
                         (map #(first (:content (first (:content %))))))]
    layer-names))

(defn http-get-capabilities [context]
  (let [url (get-in context [:query-params :url])
        res (client/get (str url "?service=WFS&version=1.1.0&request=GetCapabilities"))
        status (:status res)
        body (:body res)]
    (if (= status 200)
      (response/ok (get-capabilities->layer-names body))
      (response/error (str "Could not get capabilities from " url)))))

(defn- routes [mqtt] #{["/api/stores" :get
                        (conj intercept/common-interceptors `http-get)]
                       ["/api/stores-error" :get
