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)

View File

@@ -6,7 +6,7 @@
[auto-ap.config :as config]
[auto-ap.effects :as effects]
[pushy.core :as pushy]
[auto-ap.pushy :as p]
[auto-ap.history :as p]
[bidi.bidi :as bidi]))
(defn dev-setup []

View File

@@ -3,7 +3,7 @@
(:require [re-frame.core :as re-frame]
[cljs-http.client :as http]
[cljs.core.async :refer [<!]]
[auto-ap.pushy :as p]
[auto-ap.history :as p]
[pushy.core :as pushy]))
(re-frame/reg-fx

View File

@@ -1,4 +1,4 @@
(ns auto-ap.pushy
(ns auto-ap.history
(:require [bidi.bidi :as bidi]
[pushy.core :as pushy]
[auto-ap.routes :as routes]

View File

@@ -5,5 +5,5 @@
(def login-url
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
redirect-uri "http%3A%2F%2Flocalhost%3A3449%2Fapi%2Foauth"]
redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))