From 2198d8990da4535b6d81cf7008b85e5c14c3e0f3 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 17 Feb 2018 16:03:31 -0200 Subject: Adds service endpoints --- src/clj/queue_api/db/core.clj | 20 ++++++++++ src/clj/queue_api/routes/services.clj | 74 +++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 src/clj/queue_api/db/core.clj diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj new file mode 100644 index 0000000..2d32736 --- /dev/null +++ b/src/clj/queue_api/db/core.clj @@ -0,0 +1,20 @@ +(ns queue-api.db.core) + + +(defn add-agent [{:keys [id name primary-skillset secondary-skillset]}] + (println (str "Dummy " name))) + +(defn add-job [{:keys [id type urgent]}] + (println (str "Dummy " type))) + +(defn request-job [id] + {:job_request {:job_id "Dummy" :agent_id "Dummy"}}) + +(defn get-agent [id] + [{:type "reward_question" :jobs 2} + {:type "bills_question" :jobs 3}]) + +(defn get-queue [] + {:completed ["1" "2" "3"] + :in_process["2" "3" "4"] + :waiting ["2" "5" "6"]}) \ No newline at end of file diff --git a/src/clj/queue_api/routes/services.clj b/src/clj/queue_api/routes/services.clj index cc8ac04..326ee68 100644 --- a/src/clj/queue_api/routes/services.clj +++ b/src/clj/queue_api/routes/services.clj @@ -1,44 +1,52 @@ (ns queue-api.routes.services (:require [ring.util.http-response :refer :all] [compojure.api.sweet :refer :all] - [schema.core :as s])) + [schema.core :as s] + [queue-api.db.core :as db])) (defapi service-routes - {:swagger {:ui "/swagger-ui" + {:swagger {:ui "/swagger-ui" :spec "/swagger.json" - :data {:info {:version "1.0.0" - :title "Sample API" - :description "Sample Services"}}}} - - (context "/api" [] - :tags ["thingie"] + :data {:info {:version "1.0.0" + :title "Job Queue API" + :description "Manages agent resources"}}}} - (GET "/plus" [] - :return Long - :query-params [x :- Long, {y :- Long 1}] - :summary "x+y with query-parameters. y defaults to 1." - (ok (+ x y))) + (context "/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 a summary of an agent" + (ok (db/get-agent agent_id)))) - (POST "/minus" [] - :return Long - :body-params [x :- Long, y :- Long] - :summary "x-y with body-parameters." - (ok (- x y))) + (context "/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 for a agent" + (ok (db/request-job agent_id)))) - (GET "/times/:x/:y" [] - :return Long - :path-params [x :- Long, y :- Long] - :summary "x*y with path-parameters" - (ok (* x y))) + (context "/queue" [] + (GET "/" [] + :return {:completed [String] + :in_process[String] + :waiting [String]} + :summary "Get a summary of an agent" + (ok (db/get-queue))))) - (POST "/divide" [] - :return Double - :form-params [x :- Long, y :- Long] - :summary "x/y with form-parameters" - (ok (/ x y))) - (GET "/power" [] - :return Long - :header-params [x :- Long, y :- Long] - :summary "x^y with header-parameters" - (ok (long (Math/pow x y)))))) -- cgit v1.2.3