Add the routes and handlers for the admin panel.
This commit is contained in:
@@ -19,6 +19,22 @@
|
|||||||
(res/status 500)
|
(res/status 500)
|
||||||
(res/send (ex-message err))))))))
|
(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
|
(defn htmx-get-article-handler-factory
|
||||||
[client]
|
[client]
|
||||||
(fn [req res]
|
(fn [req res]
|
||||||
@@ -40,3 +56,45 @@
|
|||||||
(res/status 500)
|
(res/status 500)
|
||||||
(res/send (ex-message err))))))))
|
(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))
|
(handlers/index-page-handler-factory client))
|
||||||
(fn [req res]
|
(fn [req res]
|
||||||
|
|
||||||
|
(. app get "/admin"
|
||||||
|
(handlers/admin-panel-handler-factory client))
|
||||||
|
|
||||||
(. app get "/htmx/articles/:id"
|
(. app get "/htmx/articles/:id"
|
||||||
(handlers/htmx-get-article-handler-factory client))
|
(handlers/htmx-get-article-handler-factory client))
|
||||||
|
|
||||||
|
(. app get "/htmx/admin/rows/article/:id/"
|
||||||
|
(handlers/htmx-get-article-row-handler-factory client))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defn start
|
(defn start
|
||||||
|
|||||||
Reference in New Issue
Block a user