(ns auto-ap.routes.companies
  (:require [auto-ap.db.companies :as companies]
            [auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
            [auto-ap.entities.companies :as entity]
            [compojure.core :refer [GET PUT context defroutes
                                    wrap-routes]]))


(defroutes routes
  (wrap-routes
   (context "/companies" []
            (GET "/" []
                 {:status 200
                  :body (pr-str (companies/get-all))
                  :headers {"Content-Type" "application/edn"}})
            (wrap-spec
             (PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
                  {:status 200
                   :body (pr-str (companies/upsert id edn-params))
                   :headers {"Content-Type" "application/edn"}})
             ::entity/company))
   wrap-secure))
