Add a drawer, routes, handlers to update an article.
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user