Reorganize API endpoints

This commit is contained in:
Teemu Patja 2017-01-30 21:26:02 +02:00
parent fb136e656d
commit c60db00f6d
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 70 additions and 66 deletions

View File

@ -36,7 +36,17 @@
:description "commitETH API"}}}}
(context "/api" []
(POST "/user/address" []
(context "/bounties" []
(GET "/all" []
(ok (bounties-db/list-all-bounties))))
(context "/user" []
(GET "/" []
:auth-rules authenticated?
:current-user user
(ok {:user (users/get-user (:id user))}))
(POST "/address" []
:auth-rules authenticated?
:body-params [user-id :- String, address :- String]
:summary "Update user address"
@ -44,22 +54,16 @@
(if (= 1 result)
(ok)
(internal-server-error))))
(GET "/user" []
:auth-rules authenticated?
:current-user user
(ok {:user (users/get-user (:id user))}))
(GET "/user/repositories" []
(GET "/repositories" []
:auth-rules authenticated?
:current-user user
(ok {:repositories (->> (github/list-repos (:token user))
(map #(select-keys %
[:id :html_url :name :full_name :description])))}))
(GET "/repositories" []
(GET "/enabled-repositories" []
:auth-rules authenticated?
:current-user user
(ok (repositories/get-enabled (:id user))))
(GET "/bounties" []
(ok (bounties-db/list-all-bounties)))
(POST "/bounty/:issue{[0-9]{1,9}}/payout" {:keys [params]}
:auth-rules authenticated?
:current-user user
@ -71,7 +75,7 @@
(if (= 1 result)
(ok)
(internal-server-error))))
(GET "/user/bounties" []
(GET "/bounties" []
:auth-rules authenticated?
:current-user user
(ok (map #(conj % (let [balance (:balance %)]
@ -97,4 +101,4 @@
(repositories/update-hook-id repo-id (:id created-hook))
(bounties/add-bounties-for-existing-issues result)))
(github/remove-webhook repo (:hook_id result) token))
result)))))
result))))))

View File

@ -64,7 +64,7 @@
(fn [{:keys [db]} [_]]
{:db db
:http {:method GET
:url "/api/bounties"
:url "/api/bounties/all"
:on-success #(dispatch [:set-bounties %])}}))
(reg-event-fx
@ -72,7 +72,7 @@
(fn [{:keys [db]} [_ issue-id payout-hash]]
{:db db
:http {:method POST
:url (str/format "/api/bounty/%s/payout" issue-id)
:url (str/format "/api/user/bounty/%s/payout" issue-id)
:on-success #(println %)
:params {:payout-hash payout-hash}}}))
@ -133,7 +133,7 @@
(fn [{:keys [db]} [_]]
{:db db
:http {:method GET
:url "/api/repositories"
:url "/api/user/enabled-repositories"
:on-success #(dispatch [:set-enabled-repos %])}}))
(reg-event-fx
@ -142,7 +142,7 @@
(println "toggle-repo" repo)
{:db db
:http {:method POST
:url "/api/repository/toggle"
:url "/api/user/repository/toggle"
:on-success #(println %)
:params (select-keys repo [:id :login :full_name :name])}}))