summaryrefslogtreecommitdiffstats
path: root/src/controller/routes.phel
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-09-09 23:09:18 -0700
committerGravatar Tom Willemse2026-09-09 23:09:18 -0700
commit24fc3ae9367fab7468cd3600cc4c3f61ad9506f6 (patch)
tree1bfa2a13f2397db28b8c668f2e0b6cc6bd965b59 /src/controller/routes.phel
parent787dd1b1c0d370825aeac3aa976694541f931c52 (diff)
downloadlezer-24fc3ae9367fab7468cd3600cc4c3f61ad9506f6.tar.gz
lezer-24fc3ae9367fab7468cd3600cc4c3f61ad9506f6.zip
view/book: Show some info about the book
Diffstat (limited to 'src/controller/routes.phel')
-rw-r--r--src/controller/routes.phel16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index 6e825fe..d891ec4 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -26,6 +26,15 @@
(pdo/execute params)
(pdo/fetch-all))))
+(defn- get-sessions-by-book [book]
+ (let [[query params] (sql/format
+ {:select [:*]
+ :from [:books_sessions]
+ :where [:= :book_id (:id book)]})]
+ (-> (pdo/prepare conn query)
+ (pdo/execute params)
+ (pdo/fetch-all))))
+
(defn- create-book [fields]
(pdo/insert conn :books fields))
@@ -90,9 +99,12 @@
:body (index-html books router)})))
(defn book-view-handler [request]
- (let [id (get-in request [:attributes :match :path-params :id])]
+ (let [id (get-in request [:attributes :match :path-params :id])
+ book (get-book-by-id id)]
(h/response-from-map {:status 200
- :body (book-html (get-book-by-id id))})))
+ :body (book-html (conj book
+ {:authors (get-authors-by-book book)
+ :sessions (get-sessions-by-book book)}))})))
(defn book-create-handler [request]
(let [title (get-in request [:parsed-body "title"])