   "Celestial systems api"
   (:refer-clojure :exclude [type])
   (:require 
+    [celestial.security :refer (current-user)]
+    [ring.util.codec :refer (base64-decode)]
+    [clojure.data.json :as json]
     [celestial.persistency :as p]
     [cemerick.friend :as friend]
     [celestial.persistency.systems :as s]
+    [es.systems :as es]
     [celestial.model :refer (sanitized-envs)] 
     [clojure.core.strint :refer (<<)] 
     [slingshot.slingshot :refer  [throw+ try+]] 


(defroutes- environments {:path "/environments" :description "Operations on environments"}
  (GET- "/environments" [] {:nickname "getEnvironments" :summary "Get all environments"}
     (let [{:keys [username]} (friend/current-authentication)
           {:keys [envs] :as user} (p/get-user username)]
        (success {:environments (sanitized-envs (into #{} envs))}))))


(defc "/systems" [:env] (keyword v))
 
(defn working-username  []
   (let [{:keys [username]} (current-user) ] 
     username))

(defn systems-range
  "Get systems in range" 
  [from to]
  {:pre [(> from -1)]}
  (let [systems (into [] (s/systems-for (working-username))) to* (min to (count systems))]
    (when-not (empty? systems)
      (if (and (contains? systems from) (contains? systems (- to* 1)))
        {:meta {:total (count systems)} 
