 (ns kuona-api.handler
   (:require [cheshire.core :refer :all]
             [clojure.tools.logging :as log]
+            [clj-http.client :as http]
             [compojure.core :refer :all]
             [compojure.handler :as handler]
             [compojure.route :as route]


  (GET "/api/metrics/:mapping" [mapping search page] (get-metrics mapping search page))
  (GET "/api/metrics/:mapping/count" [mapping] (get-metrics-count mapping))
  
  (GET "/api/environments" [] (get-environments))
  (GET "/api/environments/:id" [id] (get-environment-by-id id))
  (GET "/api/environments/:id/comments" request (get-environment-comments (get-in request [:params :id])))

  [id]
  (response (value-stream)))

(defn get-api-info
  []
  (let [es (util/parse-json-body (http/get "http://localhost:9200"))]
    (response {:kuona_api      {:version (System/getProperty "kuona-api.version")}
               :elastic_search es})))

(defroutes app-routes
  (GET "/" [] (service-data))
  (GET "/api/repositories/count" [] (get-repository-count))
