       (assert (not (str/blank? name)) ; TODO: test this
               {:name name})
       (db/with-db [conn {}]
-        (let [user-id (current-user-id conn)]
+        (let [user-id (current-user-id)]
           (binding [events/*current-user* user-id]
             (let [cong-id (congregation/create-congregation! conn name)]
               (congregation/grant! conn cong-id user-id :view-congregation)

(defn download-qgis-project [request]
  (auth/with-authenticated-user request
    (require-logged-in!)
    (db/with-db [conn {:read-only? true}]
      (let [cong-id (UUID/fromString (get-in request [:params :congregation]))
            user-id (current-user-id conn)
            congregation (congregation/get-my-congregation (projections/cached-state) cong-id user-id)
            gis-user (gis-user/get-gis-user (projections/cached-state) cong-id user-id)]
        (when-not gis-user
          (forbidden! "No GIS access"))
        (let [content (qgis/generate-project {:database-host (:gis-database-host config/env)
                                              :database-name (:gis-database-name config/env)
                                              :database-schema (:congregation/schema-name congregation)
                                              :database-username (:gis-user/username gis-user)
                                              :database-password (:gis-user/password gis-user)
                                              :database-ssl-mode (:gis-database-ssl-mode config/env)})
              file-name (qgis/project-file-name (:congregation/name congregation))]
          (-> (ok content)
              (response/content-type "application/octet-stream")
              (response/header "Content-Disposition" (str "attachment; filename=\"" file-name "\""))))))))

(defroutes api-routes
  (GET "/" [] (ok "Territory Bro"))

(defn- api-command! [conn command]
  (let [command (assoc command
                       :command/time ((:now config/env))
                       :command/user (current-user-id))]
    (try
      (congregation/command! conn (projections/cached-state)
                             command)
