aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api/db/core.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clj/queue_api/db/core.clj')
-rw-r--r--src/clj/queue_api/db/core.clj30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index dc04187..765ce39 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -6,7 +6,7 @@
(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/job {:db.valueType :db.type/ref}
+ :agent/job {:db.valueType :db.type/ref}
:job/id {:db/unique :db.unique/identity}
:job/agent {:db.valueType :db.type/ref}})
@@ -23,16 +23,42 @@
(d/transact! queue-api.db.core/conn [{:job/id id
:job/type type
:job/urgent urgent
- :job/date (time/now)
+ :job/date (time/now)
:job/status :unassigned}]))
(defn request-job [id]
{:job_request {:job_id "Dummy" :agent_id "Dummy"}})
+
(defn get-agent [id]
[{:type "Dummy"
:jobs -2}])
+(defn agent-jobs [id s]
+ (let [q (d/q '[:find ?jid
+ :in $ ?id ?s
+ :where
+ [?e :agent/id ?id]
+ [?x :job/id ?jid]
+ [?x :job/status ?s]
+ [?x :job/agent ?e]]
+ @conn id s)]
+ (map #(d/entity @conn [:job/id (first %)]) q)))
+
+
+(defn q-job [u s t]
+ (let [q (->> (d/q '[:find ?d ?id
+ :in $ ?u ?s ?t
+ :where
+ [?e :job/date ?d]
+ [?e :job/id ?id]
+ [?e :job/urgent ?u]
+ [?e :job/status ?s]
+ [?e :job/type ?t]]
+ @conn u s t)
+ (sort-by first))]
+ (map #(d/entity @conn [:job/id (last %)]) q)))
+
(defn q-status [s]
(d/q '[:find ?id :in $ ?status
:where