docker-ifyed.

This commit is contained in:
Bryce Covert
2017-12-20 10:57:08 -08:00
parent ee3ea0be2c
commit 4625ef4474
15 changed files with 63 additions and 32 deletions

View File

@@ -1,28 +1,28 @@
(ns auto-ap.db.invoices
(:require [clojure.java.jdbc :as j]
[auto-ap.db.utils :refer [clj->db db->clj conn]]))
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
(defn insert-multi! [rows]
(j/insert-multi! conn
(j/insert-multi! (get-conn)
:invoices
(map clj->db rows)))
(defn get-all []
(map db->clj (j/query conn "SELECT * FROM invoices")))
(map db->clj (j/query (get-conn) "SELECT * FROM invoices")))
(defn approve []
(map db->clj (j/update! conn :invoices {:imported true} [] )))
(map db->clj (j/update! (get-conn) :invoices {:imported true} [] )))
(defn reject []
(j/delete! conn :invoices ["imported = false"]))
(j/delete! (get-conn) :invoices ["imported = false"]))
(defn get-unpaid [company]
(if company
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE imported=true AND company = ?" company]))
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true"))))
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE imported=true AND company = ?" company]))
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=true"))))
(defn get-pending [company]
(if company
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" company]))
(map db->clj (j/query conn"SELECT * FROM invoices WHERE imported=false or imported is null"))))
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" company]))
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))

View File

@@ -1,10 +1,10 @@
(ns auto-ap.db.users
(:require [clojure.java.jdbc :as j]
[clojure.edn :as edn]
[auto-ap.db.utils :refer [clj->db db->clj conn]]))
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
(defn find-or-insert! [row]
(let [user (first (j/find-by-keys conn
(let [user (first (j/find-by-keys (get-conn)
:users
{:provider_id (:provider_id row)
:provider (:provider row)}))]

View File

@@ -1,4 +1,5 @@
(ns auto-ap.db.utils
(:require [config.core :refer [env]])
(:require [clojure.string :as str]))
(defn snake->kebab [s]
@@ -21,19 +22,18 @@
[(keyword (kebab->snake (name k))) v])
x)))
(let [db-host "ec2-54-235-123-153.compute-1.amazonaws.com"
db-port 5432
db-name "dbfemhppkdksfp"]
(defn get-conn []
(let [db-host (:server (:db env))
db-port 5432
db-name "autoap"]
(println "envt" env)
(println (:db env))
(def conn {:classname "org.postgresql.Driver" ; must be in classpath
:ssl true
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
:subprotocol "postgresql"
:subname (str "//" db-host ":" db-port "/" db-name)
; Any additional
; keys are passed
; to the driver
; as driver-specific properties.
:user "tkilrhrhzlumol"
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"}))
{:classname "org.postgresql.Driver" ; must be in classpath
#_#_:ssl true
#_#_:sslfactory "org.postgresql.ssl.NonValidatingFactory"
:subprotocol "postgresql"
:subname (str "//" db-host ":" db-port "/" db-name)
:user "ap"
:password "fifteen-invoices-imported!"}))

View File

@@ -41,14 +41,14 @@
(defroutes unauthenticated-routes
(GET "/" []
(response/resource-response "index.html" {:root "public"}))
(GET "/api/oauth" {{:strs [code]} :query-params}
(GET "/api/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers}
(try
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
(http/post
{:form-params {"client_id" google-client-id
"client_secret" google-client-secret
"code" code
"redirect_uri" "http://localhost:3449/api/oauth"
"redirect_uri" (str (name scheme) "://" host "/api/oauth")
"grant_type" "authorization_code"}
:as :json})
:body)