Last active
December 19, 2015 22:39
-
-
Save ebaxt/6029232 to your computer and use it in GitHub Desktop.
Duplicate
This file contains 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
(defresource put-delete-get [system path id json-body {:keys [find-by-id find-versions | |
create update delete-by-id validation-fn | |
has-permission] :or {has-permission (constantly true)}}] | |
:allowed-methods [:put :delete :get] | |
:available-media-types ["application/json"] | |
:allowed? (fn [{{method :request-method} :request}] | |
{::instance (find-by-id system id)}) | |
:exists? ::instance | |
:can-put-to-missing? false | |
:new? false | |
:respond-with-entity? (fn [{{method :request-method} :request}] (= :put method)) | |
:put! (fn [ctx] | |
(let [old (get ctx ::instance) | |
new (update system json-body)] | |
(println "###### Old ######\n") | |
(clojure.pprint/pprint old) | |
(println "###### New ######\n") | |
(clojure.pprint/pprint new) | |
(assoc ctx ::instance new))) | |
... | |
:handle-ok (fn [ctx] | |
(println "####### Result ######") | |
(clojure.pprint/pprint (get ctx ::instance)) | |
(get ctx ::instance))) | |
=> | |
###### Old ###### | |
{:children ["51e7e7ab30043ff5187d568e"], | |
:_version 2} | |
###### New ###### | |
{:children ["51e7e7ab30043ff5187d568e" "51e7e7b630043ff5187d5690"], | |
:_version 3} | |
###### Result ###### | |
{:children | |
["51e7e7ab30043ff5187d568e" | |
"51e7e7ab30043ff5187d568e" <-- Duplicate!? | |
"51e7e7b630043ff5187d5690"], | |
:_version 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment