Last active
February 24, 2017 03:39
-
-
Save swlkr/fe72365c317433dde628baa849d6d3be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns monolith.logic.events | |
(:require [monolith.db :as db] | |
[monolith.utils :as utils] | |
[monolith.http :refer [ok]] | |
[yesql.core :as yesql] | |
[compojure.core :refer [defroutes POST]])) | |
(yesql/defqueries "sql/stripe/events.sql" (db/yesql-conn)) | |
(defn req->params [{:keys [id] :as body}] | |
(assoc body :stripe_id id :id (utils/uuid))) | |
(defn get-event [id] | |
(-> {:stripe_id id} | |
get-stripe-events-by-id | |
first)) | |
(defn exists? [stripe_id] | |
(not (nil? (get-event stripe_id)))) | |
(defn create! [{:keys [body]}] | |
(if (exists? (:id body)) | |
(ok {}) | |
(-> body | |
req->params | |
insert-stripe-event<! | |
ok))) | |
(defroutes routes | |
(POST "/events" [] create!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment