clientize.

This commit is contained in:
2023-05-05 11:28:08 -07:00
parent eacd6b4537
commit 5d0bf6a8d8
6 changed files with 56 additions and 37 deletions

View File

@@ -117,43 +117,61 @@
"type" "payment"}))
(defprotocol SolrClient
(index-documents [this xs])
(query [this q])
(delete [this]))
(defn index-documents [xs]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=15000")
{:headers {"Content-Type" "application/json"}
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str (filter identity (map datomic->solr xs)))}))
(defrecord RealSolrClient [solr-uri]
(defn query [q]
(-> (client/post (str solr-uri "/solr/invoices/query")
{:body (json/write-str {"query" q
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
:socket-timeout 30000
:connection-timeout 30000
:headers {"Content-Type" "application/json"}
:as :json}
)
:body
:response
:docs))
SolrClient
(index-documents [this xs]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=15000")
{:headers {"Content-Type" "application/json"}
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str (filter identity (map datomic->solr xs)))}))
(defn solr-delete []
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=1000")
{:headers {"Content-Type" "application/json"}
:method "POST"
:body (json/write-str {"delete" {"query" "*:*"}})})
)
(query [this q]
(-> (client/post (str solr-uri "/solr/invoices/query")
{:body (json/write-str {"query" q
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
:socket-timeout 30000
:connection-timeout 30000
:headers {"Content-Type" "application/json"}
:as :json}
)
:body
:response
:docs))
(delete [this]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=1000")
{:headers {"Content-Type" "application/json"}
:method "POST"
:body (json/write-str {"delete" {"query" "*:*"}})})))
(defrecord MockSolrClient []
SolrClient
(index-documents [this xs]
nil)
(query [this q]
nil)
(delete [this]
nil))
(def impl (if (= :solr (:solr-impl env))
(->RealSolrClient (:solr-uri env))
(->MockSolrClient )))
(defn touch-with-ledger [i]
(index-documents [i
(index-documents impl [i
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
(defn touch [i]
(index-documents [i]))
(index-documents impl [i]))