parent
bfef190c91
commit
46f017d716
@ -0,0 +1,42 @@
|
|||||||
|
(ns blog.handlers
|
||||||
|
(:require [cljs.core.async :refer [go, take!, put!, <!, >!, chan]]
|
||||||
|
[cljs.core.async.interop :refer-macros [<p!]]
|
||||||
|
[blog.db :as db]))
|
||||||
|
|
||||||
|
(defn index-page-handler-factory
|
||||||
|
[client]
|
||||||
|
(fn [req res]
|
||||||
|
(let [channel (chan)
|
||||||
|
id (.-id (.-params req))]
|
||||||
|
(go
|
||||||
|
(try
|
||||||
|
(let [articles (<! (db/get-articles client channel))]
|
||||||
|
(res/status 200)
|
||||||
|
(.render res "index"
|
||||||
|
(-> {:articles articles}
|
||||||
|
(cljs.core/clj->js))))
|
||||||
|
(catch js/Error err
|
||||||
|
(res/status 500)
|
||||||
|
(res/send (ex-message err))))))))
|
||||||
|
|
||||||
|
(defn htmx-get-article-handler-factory
|
||||||
|
[client]
|
||||||
|
(fn [req res]
|
||||||
|
(let [channel (chan)
|
||||||
|
id (.-id (.-params req))]
|
||||||
|
(go
|
||||||
|
(try
|
||||||
|
(let [article (<! (db/get-article client id channel))]
|
||||||
|
(if (empty? article)
|
||||||
|
(do
|
||||||
|
(res/status 404)
|
||||||
|
(res/send (ex-message "404")))
|
||||||
|
(do
|
||||||
|
(res/status 200)
|
||||||
|
(.render res "article_briefly"
|
||||||
|
(-> {:article article :layout false}
|
||||||
|
(cljs.core/clj->js))))))
|
||||||
|
(catch js/Error err
|
||||||
|
(res/status 500)
|
||||||
|
(res/send (ex-message err))))))))
|
||||||
|
|
Loading…
Reference in new issue