Created
April 24, 2014 18:39
-
-
Save geraldodev/11264910 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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