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
|
resources/sql/youyesyet\.postgres\.sql
|
||||||
|
|
||||||
\.rebel_readline_history
|
\.rebel_readline_history
|
||||||
|
/dumps/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
|
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
|
||||||
:author "Simon Brooke"} youyesyet.routes.rest
|
: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.core.memoize :as memo]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.tools.logging :as log]
|
[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
|
was to the same address, if so use that as the `visit_id`, if not create
|
||||||
a new `visit` record."
|
a new `visit` record."
|
||||||
[request]
|
[request]
|
||||||
(let [params (massage-params request)]
|
(let [params (:params request)]
|
||||||
(log/debug "Creating intention with params: " params)
|
(log/debug "Creating intention with params: " params)
|
||||||
(if-let [address-id (-> params :address_id)]
|
(if (-> request :session :user)
|
||||||
(db/create-intention!
|
(if
|
||||||
db/*db*
|
(and
|
||||||
(assoc
|
(or (:locality params)
|
||||||
params :visit_id (current-visit-id request))
|
(and (:elector-id params)
|
||||||
(db/create-intention! db/*db* 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!
|
(defn create-request-and-visit!
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
|
|
||||||
(defn local-uri? [{:keys [uri]}]
|
(defn local-uri? [{:keys [uri]}]
|
||||||
(not (re-find #"^\w+?://" uri)))
|
(not (re-find #"^\w+?://" (str uri))))
|
||||||
|
|
||||||
(defn default-headers [request]
|
(defn default-headers [request]
|
||||||
(if (local-uri? request)
|
(if (local-uri? request)
|
||||||
|
|
|
@ -482,7 +482,7 @@
|
||||||
(if-let [item (first (:outqueue db))]
|
(if-let [item (first (:outqueue db))]
|
||||||
;; if there's something in the queue, transmit it...
|
;; if there's something in the queue, transmit it...
|
||||||
(let [uri (compose-packet item)]
|
(let [uri (compose-packet item)]
|
||||||
(js/console.log (str "Transmitting item" uri))
|
(js/console.log (str "Transmitting item: " uri))
|
||||||
{:http-xhrio {:method :get
|
{:http-xhrio {:method :get
|
||||||
:uri uri
|
:uri uri
|
||||||
:format (json-request-format)
|
:format (json-request-format)
|
||||||
|
|
Loading…
Reference in a new issue