@@ -59,7 +59,9 @@ So far, only events have been somewhat implemented.
59
59
60
60
; ; and some database functions:
61
61
62
- (defn transfer! [from-account-id to-account-id amount])
62
+ (defn get-account [account-id] ... )
63
+
64
+ (defn transfer! [from-account-id to-account-id amount] ... )
63
65
64
66
(defn deposit! [account-id amount])
65
67
@@ -87,18 +89,22 @@ So far, only events have been somewhat implemented.
87
89
[[(user-exists? user-id) :forbidden " User with this id does not exist" ]
88
90
[(account-exists? account-id) :not-found " Account with this id does not exist" ]
89
91
[(user-owns-account? user-id account-id) :forbidden " User does not own this account" ]
90
- [(= currency (:currency (get-account account-id)) :incorrect " Deposit currency must match account" ]])
92
+ [(= currency (:currency (get-account account-id))) :incorrect " Deposit currency must match account" ]])
91
93
92
94
:effect
93
95
(fn [{:keys [account-id amount]}]
94
- (deposit! account-id amount))}
96
+ (deposit! account-id amount))
97
+
98
+ :return
99
+ (fn [{:keys [account-id]}]
100
+ (get-account account-id))}
95
101
96
102
{:id :transfer!
97
103
98
104
:params {:user-id :bank.user/id
99
105
:from-account-id :bank.account/id
100
106
:to-account-id :bank.account/id
101
- :amount (and integer? pos?)})}
107
+ :amount (and integer? pos?)}
102
108
103
109
:conditions
104
110
(fn [{:keys [user-id from-account-id to-account-id amount]}]
@@ -107,11 +113,12 @@ So far, only events have been somewhat implemented.
107
113
[(user-owns-account? user-id from-account-id) :forbidden " User does not own this account" ]
108
114
[(account-exists? from-account-id) :incorrect " Account with this id does not exist" ]
109
115
[(>= (:balance (get-account from-account-id)) amount) :conflict " Insufficient funds in account" ]
110
- [(= (:currency (get-account from-account-id)
111
- (:currency (get-account to-account-id)) :conflict " Currency of accounts must match" ]])
116
+ [(= (:currency (get-account from-account-id))
117
+ (:currency (get-account to-account-id))) :conflict " Currency of accounts must match" ]])
112
118
113
- :effect (fn [{:keys [from-account-id to-account-id amount]}]
114
- (transfer! from-account-id to-account-id amount)}]}])
119
+ :effect
120
+ (fn [{:keys [from-account-id to-account-id amount]}]
121
+ (transfer! from-account-id to-account-id amount))}])
115
122
116
123
117
124
; ; register our events
0 commit comments