(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" (let [jobs (db/sum-agent agent_id)] (map (fn [x] {:type (first x) :jobs (last x)}) jobs)))) (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 s/Any :agent_id String}} :body-params [agent_id :- String] :summary "Request a job to a given agent" (let [j (db/dequeue-job agent_id)] (if (nil? j) (bad-request {:message "Agent does not exist"}) (ok {:job_request {:job_id j :agent_id 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)))))