refactoring + new tests
This commit is contained in:
+8
-1
@@ -46,7 +46,7 @@
|
||||
(map #(+ (second %) (.get (Calendar/getInstance) (first %)))
|
||||
{Calendar/YEAR 0, Calendar/MONTH 1, Calendar/DAY_OF_MONTH 0}))
|
||||
|
||||
(defn create-response
|
||||
(defn- create-response
|
||||
([success] {:success success})
|
||||
([success message & params]
|
||||
(assoc (create-response success) :message (apply format message params))))
|
||||
@@ -59,6 +59,13 @@
|
||||
(str domain "/" (storage/create-short-url token {:year year :month month :day day :title title}))
|
||||
(str domain (url year month day title))))))
|
||||
|
||||
(defn version-manager [f params]
|
||||
(if-let [version (:version params)]
|
||||
(f (if (and (:noteID params) (< (Double/parseDouble version) 1.3))
|
||||
(assoc params :noteID (sreplace (params :noteID) #" " "/"))
|
||||
params))
|
||||
(create-response false "API version expected")))
|
||||
|
||||
(defn get-note [{:keys [noteID]}]
|
||||
(if (storage/note-exists? noteID)
|
||||
(let [note (storage/get-note noteID)]
|
||||
|
||||
+3
-11
@@ -90,27 +90,19 @@
|
||||
{:headers {"Content-Type" ctype}
|
||||
:body content})
|
||||
|
||||
(defn version-manager [f params]
|
||||
(generate-string
|
||||
(if-let [version (:version params)]
|
||||
(f (if (and (:noteID params) (< (Float/parseFloat version) 1.3))
|
||||
(assoc params :noteID (sreplace (params :noteID) #" " "/"))
|
||||
params))
|
||||
(api/create-response false "API version expected"))))
|
||||
|
||||
(defroutes api-routes
|
||||
|
||||
(GET "/" [] (layout (get-message :api-title)
|
||||
(md-node :article (slurp "API.md"))))
|
||||
|
||||
(GET "/note" {params :params}
|
||||
(version-manager api/get-note params))
|
||||
(generate-string (api/version-manager api/get-note params)))
|
||||
|
||||
(POST "/note" {params :params}
|
||||
(version-manager api/post-note params))
|
||||
(generate-string (api/version-manager api/post-note params)))
|
||||
|
||||
(PUT "/note" {params :params}
|
||||
(version-manager api/update-note params)))
|
||||
(generate-string (api/version-manager api/update-note params))))
|
||||
|
||||
(defroutes app-routes
|
||||
(context "/api" [] api-routes)
|
||||
|
||||
Reference in New Issue
Block a user