Checkpoint on improvemenths.

This commit is contained in:
Bryce Covert
2017-12-08 08:01:37 -08:00
parent ef4dd52a42
commit dc5eb781a9
3 changed files with 19 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
(ns auto-ap.db.invoices (ns auto-ap.db.invoices
(:require [clojure.java.jdbc :as j] (: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] (defn insert-multi! [rows]
(j/insert-multi! conn (j/insert-multi! conn
@@ -10,3 +10,7 @@
(defn get-all [] (defn get-all []
(map db->clj (j/query conn "SELECT * FROM invoices"))) (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")))

View File

@@ -22,11 +22,13 @@
x))) x)))
(def conn {:classname "org.postgresql.Driver" ; must be in classpath (def conn {:classname "org.postgresql.Driver" ; must be in classpath
:ssl true :dbtype "postgresql"
:sslfactory "org.postgresql.ssl.NonValidatingFactory" :ssl true
:subprotocol "postgresql" :sslfactory "org.postgresql.ssl.NonValidatingFactory"
:subname (str "//ec2-54-235-123-153.compute-1.amazonaws.com:5342/dbfemhppkdksfp") :host "ec2-54-235-123-153.compute-1.amazonaws.com"
:port 5342
:dbname "dbfemhppkdksfp"
; Any additional keys are passed to the driver ; Any additional keys are passed to the driver
; as driver-specific properties. ; as driver-specific properties.
:user "tkilrhrhzlumol" :user "tkilrhrhzlumol"
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"}) :password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"})

View File

@@ -3,6 +3,7 @@
[compojure.route :as route] [compojure.route :as route]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.string :as str] [clojure.string :as str]
[auto-ap.db.invoices :as invoices]
[auto-ap.parse :as parse] [auto-ap.parse :as parse]
[ring.middleware.multipart-params :as mp] [ring.middleware.multipart-params :as mp]
[ring.util.response :as response] [ring.util.response :as response]
@@ -12,32 +13,6 @@
[ring.middleware.edn :refer [wrap-edn-params]] [ring.middleware.edn :refer [wrap-edn-params]]
[clojure.java.jdbc :as j])) [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 (defroutes app-routes
(GET "/" [] (response/resource-response "index.html" {:root "public"})) (GET "/" [] (response/resource-response "index.html" {:root "public"}))
(GET "/api/invoices" [] (GET "/api/invoices" []
@@ -45,9 +20,13 @@
:body (pr-str (invoices/get-all)) :body (pr-str (invoices/get-all))
:headers {"Content-Type" "application/edn"}}) :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]} (POST "/api/invoices" {:keys [edn-params]}
(invoices/insert-multi! (:rows edn-params)) (invoices/insert-multi! (:rows edn-params))
{:status 200 {:status 200
:body (pr-str (invoices/get-all)) :body (pr-str (invoices/get-all))
:headers {"Content-Type" "application/edn"}}) :headers {"Content-Type" "application/edn"}})