From f78df3d232f7248be0c54fd44d4f0a2219a5d1d8 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 2 Apr 2024 14:52:24 +0300 Subject: [PATCH] Add the routes and handlers for the admin panel. --- src/main/blog/handlers.cljs | 58 +++++++++++++++++++++++++++++++++++++ src/main/blog/server.cljs | 6 ++++ 2 files changed, 64 insertions(+) diff --git a/src/main/blog/handlers.cljs b/src/main/blog/handlers.cljs index 6a0a00c..7eef0c1 100644 --- a/src/main/blog/handlers.cljs +++ b/src/main/blog/handlers.cljs @@ -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 ( {: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 ( {: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 ( {:article article :layout false} + (cljs.core/clj->js)))))) + (catch js/Error err + (res/status 500) + (res/send (ex-message err)))))))) + diff --git a/src/main/blog/server.cljs b/src/main/blog/server.cljs index 01c04bf..5cc0143 100644 --- a/src/main/blog/server.cljs +++ b/src/main/blog/server.cljs @@ -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