diff options
author | Tim <contact@bytim.eu> | 2025-05-15 20:09:08 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-05-15 20:09:08 +0200 |
commit | 0d62cec021750e42e1b14f6a0d33db998fbffe4a (patch) | |
tree | ebbade144318e547abaa252f00ca3911c47d85c6 /src/chef/pages | |
parent | 587976b8a16b884ccd7b7dba9ff7209772d395ce (diff) | |
download | chef-0d62cec021750e42e1b14f6a0d33db998fbffe4a.tar.xz chef-0d62cec021750e42e1b14f6a0d33db998fbffe4a.zip |
Change oauth flow + create api route to create new category
Diffstat (limited to 'src/chef/pages')
-rw-r--r-- | src/chef/pages/admin.clj | 21 | ||||
-rw-r--r-- | src/chef/pages/admin/api.clj | 13 | ||||
-rw-r--r-- | src/chef/pages/home.clj | 12 |
3 files changed, 30 insertions, 16 deletions
diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj index 9aaade3..fb6eeee 100644 --- a/src/chef/pages/admin.clj +++ b/src/chef/pages/admin.clj @@ -17,15 +17,20 @@ [:input {:type :text :placeholder "Frage" :style {:display :inline-block :width :auto}}] ; TODO: only show when category has children - [:img {:src "/static/icons/plus.svg" :height "30em" - :style {:vertical-align :middle - :margin-left "1em"}}]]] + [:img {:src "/static/icons/plus.svg" :height "30em" + :style {:vertical-align :middle + :margin-left "1em"} + :hx-post "/api/admin/create-category" + :hx-swap "none"}]]] [:h2 "Rezepte"] [:i "Coming soon..."])) (defn handler [req] - (cutils/auth-only req - (-> (render) - html/html - str - ruresp/response))) + (let [access-token (get-in req [:oauth2/access-tokens :auth]) + resp (-> (render) + html/html + str + ruresp/response)] + (if (some? access-token) + (assoc resp :session (assoc (:session req) :oauth-token access-token)) + (cutils/auth-only req resp)))) diff --git a/src/chef/pages/admin/api.clj b/src/chef/pages/admin/api.clj new file mode 100644 index 0000000..3e2ccbd --- /dev/null +++ b/src/chef/pages/admin/api.clj @@ -0,0 +1,13 @@ +(ns chef.pages.admin.api + (:require [chef.utils :as cutils] + [chef.database :as cdb] + [next.jdbc :as jdbc] + [honey.sql :as sql] + [ring.util.response :as ruresp])) + +(defn create-category [req] + (cutils/auth-only req + (jdbc/execute! @cdb/db (sql/format {:insert-into [:categories] + :values [{:name "New category"}]})) + (-> (ruresp/created "Created.") + (ruresp/header "Refresh" "0")))) diff --git a/src/chef/pages/home.clj b/src/chef/pages/home.clj index 2060668..748c60c 100644 --- a/src/chef/pages/home.clj +++ b/src/chef/pages/home.clj @@ -27,11 +27,7 @@ [:div {:id "search-results"}]])) (defn handler [req] - (let [access-token (get-in req [:oauth2/access-tokens :auth]) - resp (-> (render) - html/html - str - ruresp/response)] - (if (some? access-token) - (assoc resp :session (assoc (:session req) :oauth-token access-token)) - resp))) + (-> (render) + html/html + str + ruresp/response)) |