From 200b378146d4d6fdad4218bf950a61ac20c35b86 Mon Sep 17 00:00:00 2001 From: Aditya Athalye Date: Mon, 2 Sep 2024 02:15:15 +0530 Subject: [PATCH] Use GET for the delete path for convenience, just like the OG repo has done. This is obviously bad. We can use HTMX to fix it cleanly, instead of doing the usual workarounds. --- src/usermanager/layouts/core.clj | 6 +++--- src/usermanager/router/core.clj | 2 +- test/usermanager/handlers/user_test.clj | 2 +- test/usermanager/router/core_test.clj | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/usermanager/layouts/core.clj b/src/usermanager/layouts/core.clj index ce7d558..2a702ab 100644 --- a/src/usermanager/layouts/core.clj +++ b/src/usermanager/layouts/core.clj @@ -71,9 +71,9 @@ [:tr (for [field [id name email department action]] [:td field])])) users) - [:tr [:td {:colspan (count table-headers)}] - "No users exist but " - [:a {:href "/user/form"} "new ones can be added"]"."])]])) + (list [:tr [:td {:colspan (count table-headers)} + "No users exist but " + [:a {:href "/user/form"} "new ones can be added"] "."]]))]])) (def uri->page-name {"/" "Home" diff --git a/src/usermanager/router/core.clj b/src/usermanager/router/core.clj index 07a1a52..59c4497 100644 --- a/src/usermanager/router/core.clj +++ b/src/usermanager/router/core.clj @@ -34,7 +34,7 @@ [_] handlers/default) -(defmethod router [:delete "/user/delete/:id"] +(defmethod router [:get "/user/delete/:id"] [_] (middleware/wrap-route-id-params handlers/delete-by-id diff --git a/test/usermanager/handlers/user_test.clj b/test/usermanager/handlers/user_test.clj index dda20ee..c7d7df1 100644 --- a/test/usermanager/handlers/user_test.clj +++ b/test/usermanager/handlers/user_test.clj @@ -57,5 +57,5 @@ (is (= {:status 200 :trace-redirects [(str base-uri "user/list")] :body ""} - (-> (http/delete (str base-uri "user/delete/42")) + (-> (http/get (str base-uri "user/delete/42")) (select-keys [:status :body :trace-redirects]))))))) diff --git a/test/usermanager/router/core_test.clj b/test/usermanager/router/core_test.clj index 86a5df7..5b1f715 100644 --- a/test/usermanager/router/core_test.clj +++ b/test/usermanager/router/core_test.clj @@ -129,7 +129,7 @@ :application/view "list"} ;; 3. DELETE - (handle {:request-method :delete + (handle {:request-method :get :uri "/user/delete/2" :application/component {:database db}}) {:status 303 @@ -190,7 +190,7 @@ :application/view "list"} ;; Delete the lone user - (handle {:request-method :delete + (handle {:request-method :get :uri "/user/delete/1" :params {:id 1} ; We assume setup creates at least one user :application/component {:database db}})