56 lines
2.6 KiB
Clojure
56 lines
2.6 KiB
Clojure
(ns auto-ap.routes.invoices
|
|
(:require [auto-ap.db.companies :as companies]
|
|
[auto-ap.db.invoices :as invoices]
|
|
[auto-ap.parse :as parse]
|
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
|
[compojure.core :refer [GET POST context defroutes
|
|
wrap-routes]]))
|
|
|
|
(defroutes routes
|
|
(wrap-routes
|
|
(context "/invoices" []
|
|
(GET "/" []
|
|
{:status 200
|
|
:body (pr-str (invoices/get-all))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
|
|
(GET "/unpaid" {:keys [query-params] :as r}
|
|
{:status 200
|
|
:body (pr-str (invoices/get-unpaid (query-params "company")))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
|
|
(GET "/pending" {:keys [query-params]}
|
|
{:status 200
|
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
(POST "/" {:keys [edn-params]}
|
|
(invoices/insert-multi! (:rows edn-params))
|
|
{:status 200
|
|
:body (pr-str (invoices/get-all))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
(POST "/approve" {:keys [query-params]}
|
|
(invoices/approve)
|
|
{:status 200
|
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
(POST "/reject" {:keys [query-params]}
|
|
(invoices/reject)
|
|
{:status 200
|
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
(POST "/upload"
|
|
{{ files "file"} :params :as params}
|
|
(let [{:keys [filename tempfile]} files
|
|
companies (companies/get-all)]
|
|
(invoices/import (parse/parse-file (.getPath tempfile) filename) companies)
|
|
{:status 200
|
|
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
|
:headers {"Content-Type" "application/edn"}}))
|
|
|
|
;; Removing the export view for now...
|
|
#_(wrap-json-response (GET "/export" {:keys [query-params]}
|
|
(println query-params)
|
|
(doto (invoices/get-unpaid (query-params "company"))
|
|
println))))
|
|
wrap-secure))
|