 
 (defresource resource [store]
   :allowed-methods #{:get :delete :put}
-  :available-media-types #{"application/json" "application/edn"}
+  :available-media-types #{"text/csv" "application/json" "application/edn"}
+  :known-content-type? #{"text/csv" "application/json"}
   :authorized? (authorized? store)
   :allowed? (resource-allowed? store)
   :exists? (partial resource-exists? store)

        (allowed?* programme_id project_id programmes projects roles request-method)
        true))))

(defn index-post! [store ctx]
  (db/with-session [session (:hecuba-session store)]
    (let [request       (-> ctx :request)
          entity        (-> request decode-body)
          project_id    (-> entity :project_id)
          property_code (-> entity :property_code)
          username      (sec/session-username (-> ctx :request :session))
          user_id       (:id (users/get-by-username session username))]
      (when (and project_id property_code)
        (when-not (empty? (-> (db/execute session (hayt/select :projects (hayt/where [[= :id project_id]]))) first))


(defn resource-handle-ok [store ctx]
  (db/with-session [session (:hecuba-session store)]
    (let [{item ::item
          {mime :media-type} :representation} ctx
          request      (:request ctx)
          route-params (:route-params request)
          ids          (map :id (db/execute session (hayt/select :devices (hayt/where [[= :entity_id (:entity_id route-params)]]))))
          clean-item   (-> item
                           (assoc :device_ids ids)
                           (dissoc :user_id :devices))
          formatted-item (if (= "text/csv" mime)
                           (let [exploded-item (explode-and-sort-by-schema clean-item entity-schema)]
                             exploded-item)
                           clean-item)]
      (println "ENTITY: " formatted-item)
      (util/render-item request formatted-item))))

(defn resource-put! [store ctx]
  (db/with-session [session (:hecuba-session store)]
