From f030a32679e7291eeb3ec4925a6354767bed3694 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 1 Jun 2025 22:02:24 +0200 Subject: Add content to recipe page --- src/chef/pages/admin/api.clj | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/chef/pages/admin/api.clj') 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."))))) -- cgit v1.2.3