Skip to content

Commit

Permalink
further break down reaction q
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Jan 23, 2024
1 parent 668c0d4 commit 52c7443
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions src/main/lrsql/ops/query/reaction.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,45 @@
"ReactionTemplateError"
(ex-message ex))])))

(defn- check-reaction-gen
[{:keys [trigger-id statement]}
{reaction-id :id}
new-statement]
(let [valid? (s/valid? ::xs/statement
new-statement)]
(if-not valid?
;; Invalid Statement Error
(let [explanation
(s/explain-str ::xs/statement new-statement)]
(log/errorf
"Reaction Invalid Statement Error - Reaction ID: %s Spec Error: %s"
reaction-id
explanation)
(reaction-error-response
reaction-id
trigger-id
"ReactionInvalidStatementError"
(format "Reaction Invalid Statement Error - Spec Error: %s"
explanation)))
;; Success Response
{:reaction-id reaction-id
:trigger-id trigger-id
:statement (ru/add-reaction-metadata
new-statement
reaction-id
trigger-id)
;; Use a custom authority from the template or use
;; the trigger statement's authority
:authority (or (get new-statement "authority")
(get statement "authority"))})))

(defn- check-reaction-query
[bk tx
{:keys [statement trigger-id statement-identity]
:as _opts}
:as opts}
{:keys [ruleset]
reaction-id :id
:as _reaction}]
:as reaction}]
(let [{:keys [template]} ruleset
stored (u/str->time (get statement "stored"))
[q-success ?q-result-or-error]
Expand All @@ -110,34 +142,10 @@
(if (false? t-success)
;; Template Error
?t-result-or-error
(let [new-statement ?t-result-or-error
valid? (s/valid? ::xs/statement
new-statement)]
(if-not valid?
;; Invalid Statement Error
(let [explanation
(s/explain-str ::xs/statement new-statement)]
(log/errorf
"Reaction Invalid Statement Error - Reaction ID: %s Spec Error: %s"
reaction-id
explanation)
(reaction-error-response
reaction-id
trigger-id
"ReactionInvalidStatementError"
(format "Reaction Invalid Statement Error - Spec Error: %s"
explanation)))
;; Success Response
{:reaction-id reaction-id
:trigger-id trigger-id
:statement (ru/add-reaction-metadata
new-statement
reaction-id
trigger-id)
;; Use a custom authority from the template or use
;; the trigger statement's authority
:authority (or (get new-statement "authority")
(get statement "authority"))})))))))
(check-reaction-gen
opts
reaction
?t-result-or-error))))))

(defn- check-reaction [bk tx
{:keys [s-reactions
Expand Down

0 comments on commit 52c7443

Please sign in to comment.