File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed
src/main/java/org/couchbase/quickstart/controllers Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -176,10 +176,6 @@ public ResponseEntity transferCredits(
176176 return ResponseEntity .status (500 ).body ("Target profile not found" );
177177 }
178178
179- if (sourceProfile .getBalance () < amount ) {
180- return ResponseEntity .status (500 ).body ("Insufficient balance" );
181- }
182-
183179 TransactionOptions to = TransactionOptions .transactionOptions ();
184180 TransactionQueryOptions args = TransactionQueryOptions .queryOptions ().parameters (
185181 JsonObject .create ()
@@ -191,9 +187,12 @@ public ResponseEntity transferCredits(
191187 while (true ) {
192188 try {
193189 cluster .transactions ().run (ctx -> {
194-
195190 ctx .query ("UPDATE `" +dbProperties .getBucketName ()+"`.`_default`.`" +PROFILE +"` SET balance = balance - $amount WHERE pid = $source" , args );
196191 ctx .query ("UPDATE `" +dbProperties .getBucketName ()+"`.`_default`.`" +PROFILE +"` SET balance = balance + $amount WHERE pid = $target" , args );
192+ if (sourceProfile .getBalance () < amount ) {
193+ throw new RuntimeException ("Insufficient balance" );
194+ }
195+
197196 }, to );
198197
199198 break ;
You can’t perform that action at this time.
0 commit comments