 
 (defn find-workbook-handler [path-for]
   (resource
-    (resource-defaults)
+    (resource-defaults :cache-control "no-cache")
 
     :processable?
     (fnk [[:request params]]


(defn get-workbook-handler [path-for]
  (resource
    (resource-defaults)

    :exists?
    (fnk [db [:request [:params id]]]
      (when-let [workbook (api/workbook db id)]
        {:workbook workbook}))

    :etag (fn [{:keys [workbook]}] (-> workbook :workbook/head :version/id))

    :handle-ok
    (fnk [workbook] (render-workbook path-for workbook))

    :handle-not-found
    (error-body path-for "Workbook not found.")))

(defn put-workbook-handler [path-for]
  (fnk [conn [:params id] headers :as req]
    (if-let [new-version-id (:version-id (:params req))]
      (if-let [old-version-id (some-> (headers "if-match") decode-etag)]
        (try
          (let [wb (api/update-workbook! conn id old-version-id new-version-id)]
            {:status 204
             :headers {"etag" (str "\"" (:version/id (:workbook/head wb)) "\"")}})
          (catch Exception e
            (condp = (:type (ex-data e))
              :lens.schema/workbook-not-found (error path-for 404 "Workbook not found.")
              :lens.schema/precondition-failed (error path-for 412 "Precondition failed.")
              :lens.schema/version-not-found (error path-for 422 "Version doesn't exist."))))
        (error path-for 428 "Precondition required."))
      (error path-for 422 "Version id is missing."))))


      (find-workbook-form (path-for :find-workbook-handler))}}))

;; ---- Workbook --------------------------------------------------------------

(defn workbook-etag [path-for media-type workbook]
  (let [head (:workbook/head workbook)]
    (str (md5 (str media-type
                   (path-for :service-document-handler)
                   (workbook-path path-for workbook)
                   (version/path path-for head)))
         ";"
         (:version/id head))))

(defn update-workbook-form [path-for workbook]
  {:action (workbook-path path-for workbook)
