2019-01-11 22:10:58 +00:00
|
|
|
(ns cat.handler
|
|
|
|
(:require [cat.middleware :as middleware]
|
|
|
|
[cat.layout :refer [error-page]]
|
2019-06-08 22:53:13 +00:00
|
|
|
[cat.routes.home :refer [show-home show-relations update-relationrequest-status create-relation-request]]
|
2019-06-08 21:51:04 +00:00
|
|
|
[cat.routes.oauth :refer [oauth-init oauth-callback clear-session!]]
|
|
|
|
[cat.routes.admin :refer [set-admin! create-new-relation! create-user!]]
|
|
|
|
[compojure.core :refer [routes defroutes GET POST wrap-routes]]
|
2019-01-11 22:10:58 +00:00
|
|
|
[ring.util.http-response :as response]
|
|
|
|
[compojure.route :as route]
|
|
|
|
[cat.env :refer [defaults]]
|
2019-06-08 21:51:04 +00:00
|
|
|
[clojure.tools.logging :as log]
|
2019-01-11 22:10:58 +00:00
|
|
|
[mount.core :as mount]))
|
|
|
|
|
|
|
|
(mount/defstate init-app
|
2019-06-08 21:51:04 +00:00
|
|
|
:start ((or (:init defaults) identity))
|
|
|
|
:stop ((or (:stop defaults) identity)))
|
|
|
|
|
2019-06-08 22:53:13 +00:00
|
|
|
(defroutes public-routes
|
|
|
|
(GET "/" req (show-home req))
|
|
|
|
(GET "/relations_zeroed" [] (show-relations)))
|
|
|
|
|
|
|
|
(defroutes user-routes
|
2019-06-09 21:29:33 +00:00
|
|
|
(POST "/relation_request/:id/status" [id & body :as req] (update-relationrequest-status id body req)) ; STATUS ENUM: (open, accepted, rejected)
|
2019-06-08 22:53:13 +00:00
|
|
|
(POST "/request_relation" req (create-relation-request req)))
|
|
|
|
|
2019-06-08 21:51:04 +00:00
|
|
|
(defroutes oauth-routes
|
|
|
|
(GET "/oauth/oauth-init" req (oauth-init req))
|
|
|
|
(GET "/oauth/oauth-callback" req (oauth-callback req))
|
|
|
|
(GET "/logout" req (clear-session! "/")))
|
|
|
|
|
|
|
|
(defroutes admin-routes
|
|
|
|
(GET "/admin/enable" req (set-admin! req true))
|
|
|
|
(GET "/admin/disable" req (set-admin! req false))
|
|
|
|
(POST "/relations" req (create-new-relation! req))
|
|
|
|
(POST "/users" req (create-user! req)))
|
2019-01-11 22:10:58 +00:00
|
|
|
|
2019-06-08 22:01:51 +00:00
|
|
|
(defroutes app-routes
|
2019-06-08 22:53:13 +00:00
|
|
|
(-> public-routes
|
2019-06-08 22:01:51 +00:00
|
|
|
middleware/wrap-csrf
|
|
|
|
middleware/wrap-formats)
|
2019-06-08 22:53:13 +00:00
|
|
|
user-routes
|
|
|
|
oauth-routes
|
|
|
|
admin-routes
|
2019-06-08 22:01:51 +00:00
|
|
|
(route/not-found
|
|
|
|
(:body
|
|
|
|
(error-page {:status 404
|
|
|
|
:title "page not found"}))))
|
|
|
|
|
2019-01-11 22:10:58 +00:00
|
|
|
(mount/defstate app
|
2019-06-08 21:51:04 +00:00
|
|
|
:start
|
2019-06-08 22:01:51 +00:00
|
|
|
(-> app-routes
|
|
|
|
middleware/wrap-base))
|
2019-01-11 22:10:58 +00:00
|
|
|
|