             [territory-bro.congregation-boundary :as congregation-boundary]
             [territory-bro.db :as db]
             [territory-bro.dispatcher :as dispatcher]
-            [territory-bro.gis-db :as gis-db]
             [territory-bro.gis-user :as gis-user]
             [territory-bro.jwt :as jwt]
             [territory-bro.permissions :as permissions]


(ns territory-bro.api
  (:require [camel-snake-kebab.core :as csk]
            [clojure.test :refer :all]
            [clojure.tools.logging :as log]
            [compojure.core :refer [defroutes GET POST ANY]]
            [liberator.core :refer [defresource]]


(defn- fetch-congregation [conn state user-id congregation]
  (let [cong-id (:congregation/id congregation)]
    {:id (:congregation/id congregation)
     :name (:congregation/name congregation)
     :permissions (->> (permissions/list-permissions state user-id [cong-id])
                       (map (fn [permission]
                              [permission true]))
                       (into {}))
     ;; TODO: extract query functions
     :territories (sequence (vals (get-in state [::territory/territories cong-id])))
     :congregation-boundaries (sequence (vals (get-in state [::congregation-boundary/congregation-boundaries cong-id])))
     :subregions (sequence (vals (get-in state [::subregion/subregions cong-id])))
     :card-minimap-viewports (sequence (vals (get-in state [::card-minimap-viewport/card-minimap-viewports cong-id])))
     :users (->> (user/get-users conn {:ids (congregation/get-users state cong-id)})
                 (map (fn [user]
                        (-> (:user/attributes user)
