diff --git a/src/main/blog/handlers.cljs b/src/main/blog/handlers.cljs index 10b7490..fbe0b4f 100644 --- a/src/main/blog/handlers.cljs +++ b/src/main/blog/handlers.cljs @@ -312,6 +312,54 @@ (res/status 500) (res/send (ex-message err)))))))) +(defn htmx-create-title-validation-handler-factory + [client] + (fn [req res] + (let [channel (chan) + title (.-title (.-body req)) + content (.-content (.-body req))] + (go + (try + (let [error (cond + (= (count title) 0) + "Tittle must be nonempty!!!" + + :else + nil)] + (res/status 200) + (.render res "create_title_validation" + (-> {:error error + :title title + :layout false} + (clj->js)))) + (catch js/Error err + (res/status 500) + (res/send (ex-message err)))))))) + +(defn htmx-create-content-validation-handler-factory + [] + (fn [req res] + (let [channel (chan) + title (.-title (.-body req)) + content (.-content (.-body req))] + (go + (try + (let [error (cond + (= (count content) 0) + "Content must be nonempty!!!" + + :else + nil)] + (res/status 200) + (.render res "create_content_validation" + (-> {:error error + :content content + :layout false} + (clj->js)))) + (catch js/Error err + (res/status 500) + (res/send (ex-message err)))))))) + (defn htmx-create-article-handler-factory [client] (fn [req res] diff --git a/src/main/blog/server.cljs b/src/main/blog/server.cljs index f4a880e..30508ad 100644 --- a/src/main/blog/server.cljs +++ b/src/main/blog/server.cljs @@ -111,6 +111,20 @@ (. app post "/htmx/search/articles/" (handlers/htmx-search-articles-handler-factory client)) + (. app post "/htmx/validation/create-title/" + handlers/is-user-authorized + (handlers/htmx-create-title-validation-handler-factory client)) + + (. app use "/htmx/validation/create-title/" + (handlers/user-not-authorized-factory)) + + (. app post "/htmx/validation/create-content/" + handlers/is-user-authorized + (handlers/htmx-create-content-validation-handler-factory)) + + (. app use "/htmx/validation/create-content/" + (handlers/user-not-authorized-factory)) + (. app post "/htmx/articles/" handlers/is-user-authorized (handlers/htmx-create-article-handler-factory client)) diff --git a/views/admin_panel.hbs b/views/admin_panel.hbs index 8e39d4b..0fc6f09 100644 --- a/views/admin_panel.hbs +++ b/views/admin_panel.hbs @@ -131,15 +131,20 @@ -
+
-
+
- + +
+
+ +
-
diff --git a/views/create_title_validation.hbs b/views/create_title_validation.hbs new file mode 100644 index 0000000..967c8f3 --- /dev/null +++ b/views/create_title_validation.hbs @@ -0,0 +1,7 @@ +
+ + + {{#if error}} +
{{ error }}
+ {{/if}} +