Files
integreat/src/clj/auto_ap/routes/companies.clj
2018-07-10 22:34:58 -07:00

25 lines
1.0 KiB
Clojure

(ns auto-ap.routes.companies
(:require [auto-ap.db.companies :as companies]
[auto-ap.graphql.utils :refer [can-see-company? assert-can-see-company]]
[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 "/" r
{:status 200
:body (pr-str (filter #(can-see-company? (:identity r) (:id %)) (companies/get-all)))
:headers {"Content-Type" "application/edn"}})
(wrap-spec
(PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
(assert-can-see-company (:identity r) id)
{:status 200
:body (pr-str (companies/upsert id edn-params))
:headers {"Content-Type" "application/edn"}})
::entity/company))
wrap-secure))