diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller/routes.phel | 16 | ||||
| -rw-r--r-- | src/view/book.phel | 13 |
2 files changed, 26 insertions, 3 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"]) diff --git a/src/view/book.phel b/src/view/book.phel index 79341ad..802c46f 100644 --- a/src/view/book.phel +++ b/src/view/book.phel @@ -8,4 +8,15 @@ [:head [:title (str "Book: " (:title book) " - Lezer")]] [:body - [:h1 (:title book)]]])) + [:h1 (:title book)] + [:h2 "Authors"] + [:ul + (for [author :in (:authors book)] + [:li (:name author)])] + [:h2 "Sessions"] + [:ul + (for [session :in (:sessions book)] + [:li + (:status session) + ": " + (:started_at session)])]]])) |
