Commit eeeefaa2 authored by Johannes Knödtel's avatar Johannes Knödtel 🎶
Browse files

refactor add-price to use compojure destructuring

parent bbe86780
......@@ -53,25 +53,15 @@
valid/validate-food-request
db/add-food!))
;; TODO use compojure destructuring and type coersion
(defn translate-add-price-request [request-map]
(let [food-name-comment (get-in request-map ["food_name_comment"])
(let [food-name-comment (:food_name_comment request-map)
[food-name comment] (util/split-food-name-comment food-name-comment)]
(-> request-map
(dissoc "food_name_comment")
(assoc :food_name food-name :comment comment)
(rename-keys {"food_buy_package_size" :ammount_per_package
"food_buy_quantity" :number_of_packages
"food_buy_packageprize" :package_price})
(update-in [:ammount_per_package] util/quantity-string-to-decimal)
(update-in [:package_price] util/price-string-to-decimal)
(update-in [:number_of_packages] util/number-string-to-integer))))
(defn add-price [request]
(util/modifing-request (:form-params request) (:headers request)
#(translate-add-price-request
(assoc % :session
(Integer/parseInt (% "session"))))
(assoc :food_name food-name :comment comment))))
(defn add-price [args headers]
(util/modifing-request args headers
translate-add-price-request
valid/validate-price
db/add-price!))
......@@ -143,7 +133,18 @@
:session session}
headers))
(POST "/add-price" request (add-price request))
(POST "/add-price" [food_buy_package_size :<< util/quantity-string-to-decimal
food_buy_quantity :<< util/number-string-to-integer
food_buy_packageprize :<< util/price-string-to-decimal
food_name_comment :<< str
session :<< as-int
:as {headers :headers}]
(add-price {:ammount_per_package food_buy_package_size
:number_of_packages food_buy_quantity
:package_price food_buy_packageprize
:food_name_comment food_name_comment
:session session}
headers))
(POST "/create-session" [name :<< str]
(create-session {:name name}))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment