can edit.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.db.reminders
|
||||
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query]]
|
||||
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query execute!]]
|
||||
[clj-time.core :as time]
|
||||
[amazonica.aws.simpleemail :as ses]
|
||||
[clojure.java.jdbc :as j]
|
||||
@@ -9,6 +9,8 @@
|
||||
[honeysql.core :as sql]
|
||||
[honeysql.helpers :as helpers]))
|
||||
|
||||
(def all-keys #{:id :vendor-id :email :body :subject :sent :scheduled})
|
||||
|
||||
(defn insert [row]
|
||||
(db->clj (first (j/insert! (get-conn)
|
||||
:reminders
|
||||
@@ -17,12 +19,19 @@
|
||||
(def base-query (sql/build :select :reminders.*
|
||||
:from :reminders))
|
||||
|
||||
(defn get-all []
|
||||
(map db->clj (j/query (get-conn)
|
||||
(str
|
||||
" SELECT reminders.*, vendors.name as vendor_name "
|
||||
" FROM reminders INNER join vendors on reminders.vendor_id = vendors.id "
|
||||
" ORDER BY sent DESC, scheduled DESC"))))
|
||||
(defn get-by-id [id]
|
||||
(query (-> base-query
|
||||
(helpers/merge-where [:= :id id]))))
|
||||
|
||||
(defn update! [id data]
|
||||
(println data)
|
||||
(-> (sql/build
|
||||
:update :reminders
|
||||
:set (select-keys data all-keys )
|
||||
:where [:= :id id])
|
||||
execute!)
|
||||
(get-by-id id))
|
||||
|
||||
|
||||
(defn delete-all []
|
||||
(j/delete! (get-conn) :reminders []))
|
||||
@@ -48,7 +57,7 @@
|
||||
(defn finish [id]
|
||||
(j/update! (get-conn) :reminders {:sent (time/now)} ["id = ?" id] ))
|
||||
|
||||
(def all-keys #{:id :vendor-id :email :body :subject :sent :scheduled})
|
||||
|
||||
|
||||
(defn add-sort-by [q sort-by asc]
|
||||
(let [sort-by-key (keyword sort-by)]
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
[clj-time.periodic :as p]
|
||||
[clj-time.predicates :as pred]
|
||||
[clojure.data.json :as json]
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
[compojure.core :refer [GET PUT POST context defroutes
|
||||
wrap-routes]])
|
||||
(:import (org.joda.time DateTime)))
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
|
||||
(defroutes routes
|
||||
(context "/reminders" []
|
||||
|
||||
(POST "/send" {:keys [query-params headers body] :as x}
|
||||
(let [notification-type (get headers "x-amz-sns-message-type")]
|
||||
(println "Received notification " notification-type)
|
||||
@@ -70,9 +71,14 @@
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(wrap-routes (GET "/" {:keys [query-params]}
|
||||
{:status 200
|
||||
:body (pr-str (map replace-joda (reminders/get-all)))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
wrap-secure)))
|
||||
(wrap-routes
|
||||
(PUT "/:id" {:keys [ edn-params] {:keys [id] } :route-params}
|
||||
(let [id (if (int? id)
|
||||
id
|
||||
(Integer/parseInt id))]
|
||||
(assert (not (:sent (reminders/get-by-id id))))
|
||||
(reminders/update! id edn-params)
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
wrap-secure)))
|
||||
|
||||
Reference in New Issue
Block a user