Very close to successful transmit, but not yet working.
This commit is contained in:
parent
58958ceec7
commit
cdd3723c7b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -40,3 +40,4 @@ src/clj/youyesyet/routes/auto_json\.clj
|
|||
resources/sql/youyesyet\.postgres\.sql
|
||||
|
||||
\.rebel_readline_history
|
||||
/dumps/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
|
||||
:author "Simon Brooke"} youyesyet.routes.rest
|
||||
(:require [adl-support.core :refer [massage-params]]
|
||||
(:require [adl-support.core :refer [massage-params do-or-log-error]]
|
||||
[clojure.core.memoize :as memo]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.tools.logging :as log]
|
||||
|
@ -118,14 +118,32 @@
|
|||
was to the same address, if so use that as the `visit_id`, if not create
|
||||
a new `visit` record."
|
||||
[request]
|
||||
(let [params (massage-params request)]
|
||||
(let [params (:params request)]
|
||||
(log/debug "Creating intention with params: " params)
|
||||
(if-let [address-id (-> params :address_id)]
|
||||
(db/create-intention!
|
||||
db/*db*
|
||||
(assoc
|
||||
params :visit_id (current-visit-id request))
|
||||
(db/create-intention! db/*db* params)))))
|
||||
(if (-> request :session :user)
|
||||
(if
|
||||
(and
|
||||
(or (:locality params)
|
||||
(and (:elector-id params)
|
||||
(:address_id params)))
|
||||
(:intention params))
|
||||
(do-or-log-error
|
||||
{:status 201
|
||||
:body (with-out-str
|
||||
(print
|
||||
(hash-map
|
||||
:id
|
||||
(db/create-intention!
|
||||
db/*db*
|
||||
(assoc
|
||||
params :visit_id (current-visit-id request))
|
||||
(db/create-intention! db/*db* params)))))}
|
||||
:error-return {:status 500
|
||||
:body "Failed to create intention record"})
|
||||
{:status 400
|
||||
:body "create-intention requires params: `intention` and either `locality` or both `address_id` and `elector_id`."})
|
||||
{:status 403
|
||||
:body "You must be logged in to do that"})))
|
||||
|
||||
|
||||
(defn create-request-and-visit!
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
|
||||
(defn local-uri? [{:keys [uri]}]
|
||||
(not (re-find #"^\w+?://" uri)))
|
||||
(not (re-find #"^\w+?://" (str uri))))
|
||||
|
||||
(defn default-headers [request]
|
||||
(if (local-uri? request)
|
||||
|
|
|
@ -482,7 +482,7 @@
|
|||
(if-let [item (first (:outqueue db))]
|
||||
;; if there's something in the queue, transmit it...
|
||||
(let [uri (compose-packet item)]
|
||||
(js/console.log (str "Transmitting item" uri))
|
||||
(js/console.log (str "Transmitting item: " uri))
|
||||
{:http-xhrio {:method :get
|
||||
:uri uri
|
||||
:format (json-request-format)
|
||||
|
|
Loading…
Reference in a new issue