Skip to content

Instantly share code, notes, and snippets.

@ebaxt
Last active December 19, 2015 22:39
Show Gist options
  • Save ebaxt/6029232 to your computer and use it in GitHub Desktop.
Save ebaxt/6029232 to your computer and use it in GitHub Desktop.
Duplicate
(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