summaryrefslogtreecommitdiff
path: root/src/chef/pages/admin
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-01 22:02:24 +0200
committerTim <contact@bytim.eu>2025-06-01 22:02:24 +0200
commitf030a32679e7291eeb3ec4925a6354767bed3694 (patch)
tree5bf5f32dc45767319f63029f0d01696b20881e2c /src/chef/pages/admin
parentffb5d0b740e3fa23143ad89dab29a44d5b0acd34 (diff)
downloadchef-f030a32679e7291eeb3ec4925a6354767bed3694.tar.xz
chef-f030a32679e7291eeb3ec4925a6354767bed3694.zip
Add content to recipe page
Diffstat (limited to 'src/chef/pages/admin')
-rw-r--r--src/chef/pages/admin/api.clj28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/chef/pages/admin/api.clj b/src/chef/pages/admin/api.clj
index f1b7226..9696eb5 100644
--- a/src/chef/pages/admin/api.clj
+++ b/src/chef/pages/admin/api.clj
@@ -74,18 +74,20 @@
(ruresp/header "HX-Refresh" "true")))
(ruresp/bad-request "Bad request."))))
-;;TODO: validate request
(defn edit-recipe [req]
(cutils/auth-only req
- (if-let [id (try (Integer/parseInt (get-in req [:path-params :id]))
- (catch Exception _ nil))]
- (do (jdbc/execute! @cdb/db
- (sql/format {:update :recipes
- :set {:title (get-in req [:params "title"])
- :category (get-in req [:params "category"])
- :unit (get-in req [:params "ingredients-unit"])
- :ingredients (get-in req [:params "ingredients"])
- :preparation (get-in req [:params "preparation"])}
- :where [:= :id id]}))
- (ruresp/response "Saved."))
- (ruresp/bad-request "Bad request."))))
+ (let [id (try (Integer/parseInt (get-in req [:path-params :id]))
+ (catch Exception _ nil))
+ ingredients (get-in req [:params "ingredients"])]
+ (if (and (some? id)
+ (cutils/valid-ingredients? ingredients))
+ (do (jdbc/execute! @cdb/db
+ (sql/format {:update :recipes
+ :set {:title (get-in req [:params "title"])
+ :category (get-in req [:params "category"])
+ :unit (get-in req [:params "ingredients-unit"])
+ :ingredients ingredients
+ :preparation (get-in req [:params "preparation"])}
+ :where [:= :id id]}))
+ (ruresp/response "Saved."))
+ (ruresp/bad-request "Bad request.")))))