Allows downloading of csv files automatically.
This commit is contained in:
@@ -107,7 +107,10 @@
|
||||
|
||||
(defn results-csv-query [{:keys [query-params params]}]
|
||||
(statsd/time! [(str "export.query.time") {:tags #{(str "query:" (:query-id params))}}]
|
||||
{:body (execute-query query-params params)}))
|
||||
{:body (execute-query query-params params)
|
||||
:headers (cond-> {"Content-Type" "text/plain"}
|
||||
(or (get query-params "dl") (get query-params :dl)) (assoc "Content-Disposition" "attachment; filename=\"results.csv\""
|
||||
"Content-Type" "text/csv"))}))
|
||||
|
||||
(def routes2 {"api/" {#"queries/?" {[:query-id "/raw"] {:get :raw-query}
|
||||
[:query-id "/results/csv"] {:get :results-csv-query}
|
||||
|
||||
33
src/clj/user.fiddle
Normal file
33
src/clj/user.fiddle
Normal file
@@ -0,0 +1,33 @@
|
||||
(defn setup-randy-queries []
|
||||
(import '[java.util UUID])
|
||||
(def my-id "a4345849-00a7-424e-b393-06257d3c1820")
|
||||
|
||||
(auto-ap.routes.queries/put-query
|
||||
my-id
|
||||
(str '[:find ?an ?cn ?a ?fmt-date ?action ?payee
|
||||
:where [(ground ["SCSJ-USB9606" "SCCB-USB9598" "SCMH-USB4250" "SCM8-UB3082" "PWL-PWL2370"]) [?bac ...]]
|
||||
[(iol-ion.query/recent-date 5) ?sd]
|
||||
[(ground (clj-time.format/with-zone (clj-time.format/formatter "MMddyyyy") (clj-time.core/time-zone-for-id "America/Los_Angeles"))) ?fmt]
|
||||
[?ba :bank-account/code ?bac]
|
||||
[?ba :bank-account/number ?an]
|
||||
[?p :payment/bank-account ?ba]
|
||||
[?p :payment/date ?pd]
|
||||
[(>= ?pd ?sd)]
|
||||
[?p :payment/type :payment-type/check]
|
||||
[?p :payment/amount ?a]
|
||||
[?p :payment/check-number ?cn]
|
||||
[(clj-time.coerce/from-date ?pd) ?pd2]
|
||||
[(clj-time.format/unparse ?fmt ?pd2) ?fmt-date]
|
||||
[(ground "IS") ?action]
|
||||
[?p :payment/vendor ?v]
|
||||
[(get-some $ ?v :vendor/print-as :vendor/name) [_ ?payee]]])
|
||||
"One-off for randy"))
|
||||
|
||||
|
||||
(dc/q
|
||||
'[:find ?cd ?bal (count ?l)
|
||||
:where [?b :bank-account/locations ?bal]
|
||||
[?c :client/bank-accounts ?b]
|
||||
[?c :client/code ?cd]
|
||||
[?c :client/locations ?l]]
|
||||
(dc/db conn))
|
||||
Reference in New Issue
Block a user