Add a drawer, routes, handlers to update an article.

This commit is contained in:
2024-04-15 19:08:24 +03:00
parent 09ce47614a
commit 8ee9b5b595
5 changed files with 111 additions and 7 deletions
+37
View File
@@ -104,6 +104,43 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-get-article-edit-content-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 "admin_article_edit_content"
(-> {:article article :layout false }
(cljs.core/clj->js))))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-article-handler-factory
[client]
(fn [req res]
(let [channel (chan)
article {:id (.-id (.-params req))
:title (.-title (.-body req))
:content (.-content (.-body req))}]
(go
(try
(let [id (<! (db/update-article client article channel))]
(res/status 200)
(.redirect res 303 (str "/htmx/admin/rows/article/" id)))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-delete-article-row-handler-factory
[client]
(fn [req res]
+8 -2
View File
@@ -85,11 +85,17 @@
(. app get "/htmx/admin/rows/article/:id/"
(handlers/htmx-get-article-row-handler-factory client))
(. app get "/htmx/admin/modals/article/content/:id/"
(handlers/htmx-get-article-preview-content-handler-factory client))
(. app patch "/htmx/admin/rows/article/:id/"
(handlers/htmx-update-article-handler-factory client))
(. app delete "/htmx/admin/rows/article/:id/"
(handlers/htmx-delete-article-row-handler-factory client))
(. app get "/htmx/admin/modals/article/content/:id/"
(handlers/htmx-get-article-preview-content-handler-factory client))
(. app get "/htmx/admin/modals/article/edit-content/:id/"
(handlers/htmx-get-article-edit-content-handler-factory client))
)
(defn start