 (defn index
   [{params :params}]
   (let [entity (:entity params)
-        commodities (commodities/select-by-entity-id (env :db) (:id entity))]
+        criteria (apply-scope {:entity-id (:id entity)} :commodity)
+        commodities (commodities/search (env :db) criteria)]
     (with-layout "Commodities" {:entity entity}
       [:div.row
        [:div.col-md-6


(defn update
  [{params :params}]
  (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))))))

(defn delete
  [{params :params}]
  (let [commodity (commodities/find-by-id (env :db) (:id params))]
    (commodities/delete (env :db) (:id commodity))
    (redirect (format "/entities/%s/commodities" (:entity-id commodity)))))


(defn new-commodity
  ([{{entity-id :entity-id} :params :as req}]
   (new-commodity req (-> {:entity-id entity-id}
                          (tag-resource :commodity)
                          (authorize :new))))
  ([{{entity :entity} :params} commodity]
   (with-layout "New commodity" {:entity entity}
     [:div.row
