aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clj/queue_api/db/core.clj47
-rw-r--r--src/clj/queue_api/routes/services.clj4
2 files changed, 41 insertions, 10 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 2d32736..fa3db41 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -1,20 +1,51 @@
-(ns queue-api.db.core)
+(ns queue-api.db.core
+ (:require [datascript.core :as d]
+ [mount.core :as mount]))
+(def schema {:agent/id {:db/unique :db.unique/identity}
+ :agent/primary-skillset {:db/cardinality :db.cardinality/many}
+ :agent/secondary-skillset {:db/cardinality :db.cardinality/many}
+ :agent/jobs {:db.valueType :db.type/ref}
+ :job/id {:db/unique :db.unique/identity}
+ :job/agent {:db.valueType :db.type/ref}})
+
+(mount/defstate conn
+ :start (d/create-conn schema))
(defn add-agent [{:keys [id name primary-skillset secondary-skillset]}]
- (println (str "Dummy " name)))
+ (d/transact! queue-api.db.core/conn [{:agent/id id
+ :agent/name name
+ :agent/primary-skillset primary-skillset
+ :agent/secondary-skillset secondary-skillset}]))
(defn add-job [{:keys [id type urgent]}]
- (println (str "Dummy " type)))
+ (d/transact! queue-api.db.core/conn [{:job/id id
+ :job/type type
+ :job/urgent urgent
+ :job/status :unassigned}]))
(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}])
+ [{:type "Dummy"
+ :jobs -2}])
+
+(defn q-agent [id]
+ (d/q '[:find ?type :in $ ?id
+ :where
+ [?e :agent/id ?id]
+ [?x :job/type ?type]
+ [?x :job/agent ?e]]))
+
+(defn q-status [s]
+ (d/q '[:find ?id :in $ ?status
+ :where
+ [?e :job/status ?status]
+ [?e :job/id ?id]]
+ @conn s))
(defn get-queue []
- {:completed ["1" "2" "3"]
- :in_process["2" "3" "4"]
- :waiting ["2" "5" "6"]}) \ No newline at end of file
+ {:completed (map #(first %) (q-status :completed))
+ :processing (map #(first %) (q-status :processing))
+ :unassigned (map #(first %) (q-status :unassigned))}) \ 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 326ee68..0e94c18 100644
--- a/src/clj/queue_api/routes/services.clj
+++ b/src/clj/queue_api/routes/services.clj
@@ -44,8 +44,8 @@
(context "/queue" []
(GET "/" []
:return {:completed [String]
- :in_process[String]
- :waiting [String]}
+ :processing[String]
+ :unassigned [String]}
:summary "Get a summary of an agent"
(ok (db/get-queue)))))