 
 (defn- print-invoice
   [printable-invoice]
-  (let [pdf-stream         (ring-io/piped-input-stream
-                           (partial invoices-core/generate-pdf printable-invoice))]
+  (let [pdf-stream   (ring-io/piped-input-stream
+                     (partial invoices-core/generate-pdf printable-invoice))]
     (-> (res/response pdf-stream)
         (res/content-type "application/pdf"))))
 

    (if (or (empty? projects)
            (empty? users))
      web-util/error-not-found
      (do
        (let [invoice-to-print (printable-invoice invoice-data)]
          (invoices-db/create! connection invoice-to-print)
          (print-invoice invoice-to-print))))))

;; Endpoint for retrieving all invoices
;; GET /api/invoices/

;; GET /api/invoices/<id>/
(defn retrieve
  [request connection]
  (let [invoice-id   (Integer/parseInt (:id (:route-params request)))
        content-type (:content-type request)]
    (if-let [invoice (invoices-db/retrieve
                      connection
                      invoice-id)]
      (if (= "application/pdf" content-type)
        (print-invoice (invoice-record->invoice invoice))
        (res/response invoice))
      web-util/error-not-found)))

;; Endpoint for updating a single invoice.
