aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api/routes
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-03-08 23:06:12 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-03-08 23:06:12 -0300
commitde7cd8220c364dd816f4136a9d4c5a4d6618359d (patch)
tree8de2745e1d6d63d020330ad71f8bc6fe5e37db08 /src/clj/queue_api/routes
parentb9e1725e4f9bebce7e426431a1f8524efd026662 (diff)
downloadqueue-api-de7cd8220c364dd816f4136a9d4c5a4d6618359d.tar.gz
queue-api-de7cd8220c364dd816f4136a9d4c5a4d6618359d.tar.bz2
queue-api-de7cd8220c364dd816f4136a9d4c5a4d6618359d.zip
Better routing and mutex
Diffstat (limited to 'src/clj/queue_api/routes')
-rw-r--r--src/clj/queue_api/routes/services.clj31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/clj/queue_api/routes/services.clj b/src/clj/queue_api/routes/services.clj
index 9b8cc91..01937c1 100644
--- a/src/clj/queue_api/routes/services.clj
+++ b/src/clj/queue_api/routes/services.clj
@@ -8,9 +8,9 @@
(s/defschema new-agent
- {:id s/Str
- :name s/Str
- :primary_skillset [s/Str]
+ {:id s/Str
+ :name s/Str
+ :primary_skillset [s/Str]
:secondary_skillset [s/Str]})
(s/defschema new-job
@@ -55,21 +55,24 @@
(if (nil? (db/agent (:id body)))
(do (db/add-agent body)
{:status 201})
- (bad-request {:message "Agent id already exists"})))}
- :post {:summary "Get summary of an agent"
- :parameters {:body-params agent-id}
+ (bad-request {:message "Agent id already exists"})))}}))
+
+ (context "/agent/:id" []
+ (resource
+ {:tags ["agent"]
+ :get {:summary "Get summary of an agent"
+ :parameters {:path-params {:id s/Str}}
:responses {http-status/ok {:schema agent-sum
:description "Fetched correctly"}
http-status/not-found {:schema error-message
:description "Agent not found"}}
- :handler (fn [{body :body-params}]
- (let [a (:agent_id body)]
- (if-not (nil? (db/agent a))
- (let [jobs (db/sum-agent a)]
- (ok (map (fn [x]
- {:type (first x)
- :jobs (last x)}) jobs)))
- (not-found {:message "Agent does not exist"}))))}}))
+ :handler (fn [{{:keys [id]} :path-params}]
+ (if-not (nil? (db/agent id))
+ (let [jobs (db/sum-agent id)]
+ (ok (map (fn [x]
+ {:type (first x)
+ :jobs (last x)}) jobs)))
+ (not-found {:message "Agent does not exist"})))}}))
(context "/job" []