diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-17 22:41:00 -0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-17 22:41:00 -0200 |
commit | 64773838cb5c177994a7d86b557ea464fa06dcd2 (patch) | |
tree | bf11003fc2bd02b8dc9e534b35a8209ac4f8eabb /src/clj/queue_api/db | |
parent | 2198d8990da4535b6d81cf7008b85e5c14c3e0f3 (diff) | |
download | queue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.tar.gz queue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.tar.bz2 queue-api-64773838cb5c177994a7d86b557ea464fa06dcd2.zip |
Adds test for service.clj
Diffstat (limited to 'src/clj/queue_api/db')
-rw-r--r-- | src/clj/queue_api/db/core.clj | 47 |
1 files changed, 39 insertions, 8 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 |