summaryrefslogtreecommitdiffstats
path: root/src/controller/routes.phel
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/routes.phel')
-rw-r--r--src/controller/routes.phel17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index 5f93cc2..5016bb3 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -2,12 +2,23 @@
(:require lezer.view.main :refer [index-html])
(:require lezer.module.greet :as g)
(:require phel.router :as r)
- (:require phel.http :as h))
+ (:require phel.http :as h)
+ (:require phel.pdo))
+
+(def conn (pdo/connect "sqlite:test.db"))
+(pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255))")
(defn index-handler [req]
- (h/response-from-map {:status 200
- :body index-html}))
+ (let [books (pdo/select conn "select * from books")]
+ (h/response-from-map {:status 200
+ :body (index-html books)})))
(defn ping-handler [req]
(h/response-from-map {:status 200
:body (g/greet (str "pong - " (rand)))}))
+
+(defn book-create-handler [request]
+ (let [title (get-in request [:parsed-body "title"])]
+ (pdo/insert conn :books {:title title}))
+ (h/response-from-map {:status 201
+ :body (pdo/select conn "select * from books")}))