   (:require [environ.core :refer [env]]
             [ring.util.response :refer :all]
             [hiccup.core :refer :all]
+            [clojure.tools.logging :as log]
             [clj-money.util :refer [format-number]]
             [clj-money.web.shared :refer :all]
             [clj-money.validation :as validation]

  [{params :params}]
  (let [commodity (commodities/create
                    (env :db)
                    (select-keys params [:entity-id :name :symbol :exchange]))]
    (if (validation/has-error? commodity)
      (new-commodity {} commodity)
      (redirect (format "/entities/%s/commodities" (:entity-id commodity))))))

  (let [result (commodities/update (env :db)
                                   (select-keys
                                     params
                                     [:id :name :symbol :exchange :type]))]
    (if (validation/has-error? result)
      (edit {} result)
      (redirect (format "/entities/%s/commodities" (:entity-id result))))))
