summaryrefslogtreecommitdiff
path: root/src/chef/pages/admin/api.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/pages/admin/api.clj')
-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.")))))