|
|
@ -17,6 +17,11 @@
|
|
17
|
17
|
(defn read-tx-data [str]
|
|
18
|
18
|
(edn/read-string {:readers {'db/id (partial apply d/tempid)}} str))
|
|
19
|
19
|
|
|
|
20
|
(defn http-error [status body & {:as attrs}]
|
|
|
21
|
(into {:status status
|
|
|
22
|
:body body}
|
|
|
23
|
attrs))
|
|
|
24
|
|
|
20
|
25
|
(defroutes app-routes
|
|
21
|
26
|
(GET "/" []
|
|
22
|
27
|
{:status 200
|
|
|
@ -28,7 +33,9 @@
|
|
28
|
33
|
[:textarea {:name "facts" :cols 80 :rows 20}]
|
|
29
|
34
|
[:input {:type "submit" :value "transact!"}]])})
|
|
30
|
35
|
(GET "/facts" {{query :q} :params}
|
|
31
|
|
(pr-str (d/q (edn/read-string query) (d/db conn))))
|
|
|
36
|
(if query
|
|
|
37
|
(pr-str (d/q (edn/read-string query) (d/db conn)))
|
|
|
38
|
(http-error 400 (pr-str {:error "Missing required `q` parameter"}))))
|
|
32
|
39
|
(POST "/facts" [facts]
|
|
33
|
40
|
(pr-str (d/transact conn (read-tx-data facts)))))
|
|
34
|
41
|
|