summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.phel2
-rw-r--r--src/controller/routes.phel14
-rw-r--r--src/view/book.phel11
-rw-r--r--src/view/main.phel4
4 files changed, 30 insertions, 1 deletions
diff --git a/src/app.phel b/src/app.phel
index 0397b99..2fb1eb4 100644
--- a/src/app.phel
+++ b/src/app.phel
@@ -11,6 +11,8 @@
[["/" {:handler (fn [req]
(routes/index-handler req router))}]
["/book" {:post {:handler routes/book-create-handler}}]
+ ["/book/{id}" {:name :book
+ :get {:handler routes/book-view-handler}}]
["/book/{id}/session" {:post {:handler routes/book-session-create-handler}}]
["/author/{id}" {:name :author
:get {:handler routes/author-view-handler}}]]))
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index 096e23e..ab5d34e 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -1,6 +1,7 @@
(ns lezer.controller.routes
(:require lezer.view.main :refer [index-html])
(:require lezer.view.author :refer [author-html])
+ (:require lezer.view.book :refer [book-html])
(:require lezer.module.greet :as g)
(:require phel.router :as r)
(:require phel.http :as h)
@@ -51,6 +52,14 @@
(defn create-session-progress [fields]
(pdo/insert conn :sessions_progress fields))
+(defn- get-book-by-id [id]
+ (let [[query params] (sql/format {:select [:*]
+ :from [:books]
+ :where [:= :id id]})]
+ (-> (pdo/prepare conn query)
+ (pdo/execute params)
+ (pdo/fetch))))
+
(defn get-author-by-id [id]
(let [[query params] (sql/format {:select [:*]
:from [:authors]
@@ -80,6 +89,11 @@
(h/response-from-map {:status 200
:body (index-html books router)})))
+(defn book-view-handler [request]
+ (let [id (get-in request [:attributes :match :path-params :id])]
+ (h/response-from-map {:status 200
+ :body (book-html (get-book-by-id id))})))
+
(defn book-create-handler [request]
(let [title (get-in request [:parsed-body "title"])
subtitle (get-in request [:parsed-body "subtitle"])
diff --git a/src/view/book.phel b/src/view/book.phel
new file mode 100644
index 0000000..79341ad
--- /dev/null
+++ b/src/view/book.phel
@@ -0,0 +1,11 @@
+(ns lezer.view.book
+ (:require phel.html :refer [html doctype]))
+
+(defn book-html [book]
+ (html
+ (doctype :html5)
+ [:html
+ [:head
+ [:title (str "Book: " (:title book) " - Lezer")]]
+ [:body
+ [:h1 (:title book)]]]))
diff --git a/src/view/main.phel b/src/view/main.phel
index e25a079..9301bbc 100644
--- a/src/view/main.phel
+++ b/src/view/main.phel
@@ -31,7 +31,9 @@
[:main
[:ul
(for [b :in books]
- [:li (:title (:book b))
+ [:li
+ [:a {:href (r/generate router :book {:id (:id (:book b))})}
+ (:title (:book b))]
" by "
(authors-list (:authors b) router)
" "