aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api/routes/services.clj
blob: 7e9fc989caeb2065afd8019f61f1e8dc6e8f4e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(ns queue-api.routes.services
  (:require [ring.util.http-response :refer :all]
            [compojure.api.sweet :refer :all]
            [schema.core :as s]
            [queue-api.db.core :as db]))

(defapi service-routes
  {:swagger {:ui   "/swagger-ui"
             :spec "/swagger.json"
             :data {:info {:version     "1.0.0"
                           :title       "Job Queue API"
                           :description "Manages agent resources"}}}}

  (context "/agent" []
    :tags ["agent"]
    (PUT "/" []
      :body-params [id :- String, name :- String, primary_skillset :- [String], secondary_skillset :- [String]]
      :summary "Add a new agent"
      (db/add-agent
        {:id                 id
         :name               name
         :primary-skillset   primary_skillset
         :secondary-skillset secondary_skillset})
      (ok))
    (POST "/" []
      :return [{:type String :jobs s/Int}]
      :body-params [agent_id :- String]
      :summary "Get summary of an agent"
      (ok (db/get-agent agent_id))))

  (context "/job" []
    :tags ["job"]
    (PUT "/" []
      :body-params [id :- String, type :- String, urgent :- Boolean]
      :summary "Add a new job"
      (db/add-job {:id     id
                   :type   type
                   :urgent urgent})
      (ok))
    (POST "/" []
      :return {:job_request {:job_id String :agent_id String}}
      :body-params [agent_id :- String]
      :summary "Request a job to a given agent"
      (ok (db/request-job agent_id))))

  (context "/queue" []
    :tags ["queue"]
    (GET "/" []
      :return {:completed [String]
               :processing[String]
               :unassigned [String]}
      :summary "Get a summary of the queue"
      (ok (db/sum-queue)))))