Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created April 24, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/11264910 to your computer and use it in GitHub Desktop.
Save geraldodev/11264910 to your computer and use it in GitHub Desktop.
(defroutes rotas
#_(ANY "/empresa" []
(resource
:available-media-types ["application/edn"]
:method-allowed? (request-method-in :get :post)
:handle-ok (fn [ctx]
(k/select ent/empresa (k/fields :id :nome)))
:post! (fn [ctx]
(let [empresa (read-edn-from-body ctx)]
{::result (insert-empresa empresa)}))
:handle-created (fn [ctx] (::result ctx))))
#_(ANY "/empresa/:id" [id]
(resource
:available-media-types ["application/edn"]
:method-allowed? (request-method-in :get :put :delete)
:respond-with-entity? true
:malformed? (fn [_] (not (valid-uuid? id)))
:delete!
(fn [ctx]
(k/delete ent/empresa
(k/where {:id (java.util.UUID/fromString id)})))
:handle-ok
(by-method
:get
(fn [ctx]
(-> (k/select* ent/empresa)
(k/where {:id (java.util.UUID/fromString id)})
(k/select)
first ))
:delete
(fn [ctx]
"Registro excluído"))
:put! (fn [ctx]
(let [empresa (read-edn-from-body ctx)]
{::result (update-empresa empresa)}))
:handle-created (fn [ctx] (::result ctx)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment