Add the routes and handlers for the admin panel.

main
KKlochko 1 year ago
parent 947381b229
commit f78df3d232

@ -19,6 +19,22 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn admin-panel-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 "admin_panel"
(-> {: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]
@ -40,3 +56,45 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-get-article-row-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_row"
(-> {:article article :layout false}
(cljs.core/clj->js))))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-get-article-row-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_row"
(-> {:article article :layout false}
(cljs.core/clj->js))))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))

@ -32,8 +32,14 @@
(handlers/index-page-handler-factory client))
(fn [req res]
(. app get "/admin"
(handlers/admin-panel-handler-factory client))
(. app get "/htmx/articles/:id"
(handlers/htmx-get-article-handler-factory client))
(. app get "/htmx/admin/rows/article/:id/"
(handlers/htmx-get-article-row-handler-factory client))
)
(defn start

Loading…
Cancel
Save