Checkpoint on improvemenths.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.db.invoices
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[auto-ap.db.utils :use [clj->db db->clj conn]]))
|
||||
[auto-ap.db.utils :refer [clj->db db->clj conn]]))
|
||||
|
||||
(defn insert-multi! [rows]
|
||||
(j/insert-multi! conn
|
||||
@@ -10,3 +10,7 @@
|
||||
(defn get-all []
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices")))
|
||||
|
||||
|
||||
(defn get-pending []
|
||||
(println conn)
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=0")))
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
x)))
|
||||
|
||||
(def conn {:classname "org.postgresql.Driver" ; must be in classpath
|
||||
:ssl true
|
||||
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
|
||||
:subprotocol "postgresql"
|
||||
:subname (str "//ec2-54-235-123-153.compute-1.amazonaws.com:5342/dbfemhppkdksfp")
|
||||
:dbtype "postgresql"
|
||||
:ssl true
|
||||
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
|
||||
:host "ec2-54-235-123-153.compute-1.amazonaws.com"
|
||||
:port 5342
|
||||
:dbname "dbfemhppkdksfp"
|
||||
; Any additional keys are passed to the driver
|
||||
; as driver-specific properties.
|
||||
:user "tkilrhrhzlumol"
|
||||
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"})
|
||||
:user "tkilrhrhzlumol"
|
||||
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"})
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[compojure.route :as route]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.parse :as parse]
|
||||
[ring.middleware.multipart-params :as mp]
|
||||
[ring.util.response :as response]
|
||||
@@ -12,32 +13,6 @@
|
||||
[ring.middleware.edn :refer [wrap-edn-params]]
|
||||
[clojure.java.jdbc :as j]))
|
||||
|
||||
(defn snake->kebab [s]
|
||||
(str/replace s #"_" "-"))
|
||||
|
||||
(defn kebab->snake [s]
|
||||
(str/replace s #"-" "_"))
|
||||
|
||||
(defn db->clj [x]
|
||||
(into {}
|
||||
(map
|
||||
(fn [[k v]]
|
||||
[(keyword (snake->kebab (name k))) v])
|
||||
x)))
|
||||
|
||||
(defn clj->db [x]
|
||||
(into {}
|
||||
(map
|
||||
(fn [[k v]]
|
||||
[(keyword (kebab->snake (name k))) v])
|
||||
x)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/" [] (response/resource-response "index.html" {:root "public"}))
|
||||
(GET "/api/invoices" []
|
||||
@@ -45,9 +20,13 @@
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices/pending" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/invoices" {:keys [edn-params]}
|
||||
(invoices/insert-multi! (:rows edn-params))
|
||||
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
Reference in New Issue
Block a user