 (defroutes routes
   (resources "/")
   (resources "/react" {:root "react"})
+  (context "/api/v1" req
+    (POST "/login" {{:keys [username password]} :params}
+      (ctrl/login username password))
+    (POST "/adminLogin" req (ctrl/admin-login req))
 
-  (POST "/api/v1/login" {{:keys [username password]} :params}
-        (ctrl/login username password))
-  (POST "/api/v1/adminLogin" req (ctrl/admin-login req))
-  (POST "/api/v1/locations" req (ctrl/create-location req))
-  (POST "/api/v1/socialgroups" req (ctrl/create-social-group req))
-  (POST "/api/v1/individuals" req (ctrl/create-individual req))
-  (POST "/api/v1/relationships" req (ctrl/create-relationship req))
-  (POST "/api/v1/residencies" req (ctrl/create-residency req))
-  (POST "/api/v1/memberships" req (ctrl/create-membership req))
+    (context "/locations" []
+        (GET "/" [uuid] (ctrl/locations "HIERARCHY_ROOT"))
+      (GET "/:uuid" [uuid] (ctrl/locations uuid))
+      (POST "/" req (ctrl/create-location req)))
 
-  (POST "/api/v1/visit" req (ctrl/start-visit req))
-  (POST "/api/v1/pregnancyObservation" req "not implemented")
-  (POST "/api/v1/pregnancyResult" req "not impmlented")
-  (POST "/api/v1/pregnancyOutcome" req "not implemented")
-  (POST "/api/v1/inMigration" req "not implemented")
-  (POST "/api/v1/outMigration" req "not implemented")
-  (POST "/api/v1/death" req "not implemented")
+           ;;; Users
+    (context "/fieldworker" []
+      (GET "/" []
 
-  (GET "/api/v1/projectCodes" req "not implemented")
-  (GET "/api/v1/user" req "not implemented")
-  (GET "/api/v1/fieldworker" req "not implemented")
+        )
+      (POST "/" []
+        ))
+    (context "/user" []
+      (GET "/" [])
+      (POST "/" []))
+           ;;; Project
+    (context "/project-code" []
+        (GET "/" [])
+      (POST "/" []))
+           ;;; Entities
+    (context "/location-hierarchy" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/location-hierarchy-levels" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/location" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/individual" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/social-group" []
+      (GET "/" [])
+      (POST "/" []))
+           ;;; Relations
+    (context "/membership" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/residency" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/relationship" []
+      (GET "/" [])
+      (POST "/" []))
+           ;;; Events
+    (context "/visit" []
+      (GET "/" [])
+      (POST "/" []))
+    (context "/pregnancy" []
+      (context "/observation" []
+        (GET "/" [])
+        (POST "/" []))
+      (context "/outcome" []
+        (GET "/" [])
+        (POST "/" [])))
+    (context "/migration" []
+      (context "/in" []
+        (GET "/" [])
+        (POST "/" []))
+      (context "/out" []
+        (GET "/" [])
+        (POST "/" [])))
 
-  (PUT "/api/v1/entity/audit" req "not implemented")
-  (GET "/api/v1/entity" req "not implemented")
-  (POST "/api/v1/entity" req "not implemented")
+    (POST "/socialgroups" req (ctrl/create-social-group req))
+    (POST "/individuals" req (ctrl/create-individual req))
+    (POST "/relationships" req (ctrl/create-relationship req))
+    (POST "/residencies" req (ctrl/create-residency req))
+    (POST "/memberships" req (ctrl/create-membership req))
 
-  (GET "/api/v1/locationHierarchy" req (ctrl/get-location-hierarchies))
-  (GET "/api/v1/locationHierarchyLevels" req (ctrl/get-location-hierarchy-levels))
+    (POST "/visit" req (ctrl/start-visit req))
+    (POST "/pregnancyObservation" req "not implemented")
+    (POST "/pregnancyResult" req "not impmlented")
+    (POST "/pregnancyOutcome" req "not implemented")
+    (POST "/inMigration" req "not implemented")
+    (POST "/outMigration" req "not implemented")
+    (POST "/death" req "not implemented")
 
-  (GET "/api/v1/locations/:uuid" [uuid] (ctrl/locations uuid))
-  (GET "/api/v1/locations/" [uuid] (ctrl/locations "HIERARCHY_ROOT"))
-  (GET "/api/v1/individuals-by-location/:uuid" [uuid] (ctrl/individuals-by-location uuid))
+    (GET "/projectCodes" req "not implemented")
+    (GET "/user" req "not implemented")
+    (GET "/fieldworker" req "not implemented")
+
+    (PUT "/entity/audit" req "not implemented")
+    (GET "/entity" req "not implemented")
+    (POST "/entity" req "not implemented")
+
+    (GET "/locationHierarchy" req (ctrl/get-location-hierarchies))
+    (GET "/locationHierarchyLevels" req (ctrl/get-location-hierarchy-levels))
+
+    (GET "/individuals-by-location/:uuid" [uuid] (ctrl/individuals-by-location uuid)))
   (GET "/*" req (page)))
 
 (def http-handler

            [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
            [environ.core :refer [env]]
            [ring.adapter.jetty :refer [run-jetty]]
            [ohds.controller :as ctrl])
  (:gen-class))


(deftemplate page (io/resource "index.html") []
  [:body] (if is-dev? inject-devmode-html identity))

(ns ohds.server
  (:require [clojure.java.io :as io]
            [ohds.dev :refer [is-dev? inject-devmode-html browser-repl start-figwheel]]
            [compojure.core :refer [GET POST PUT defroutes contex]]
            [compojure.route :refer [resources]]
            [net.cgrand.enlive-html :refer [deftemplate]]
            [net.cgrand.reload :refer [auto-reload]]
