-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: simplifying workflow samples #1716
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,6 @@ public Wallet deposit(int amount) { | |
} | ||
} | ||
|
||
public record Balance(int value) { | ||
} | ||
|
||
// end::wallet[] | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(WalletEntity.class); | ||
|
@@ -36,11 +33,10 @@ public Effect<String> create(@PathVariable String id, @PathVariable int initBala | |
|
||
@PatchMapping("/withdraw/{amount}") // <2> | ||
public Effect<String> withdraw(@PathVariable int amount) { | ||
var newBalance = currentState().balance() - amount; | ||
if (newBalance < 0) { | ||
Wallet updatedWallet = currentState().withdraw(amount); | ||
if (updatedWallet.balance < 0) { | ||
return effects().error("Insufficient balance"); | ||
} else { | ||
Wallet updatedWallet = currentState().withdraw(amount); | ||
// end::wallet[] | ||
logger.info("Withdraw walletId: [{}] amount -{} balance after {}", currentState().id(), amount, updatedWallet.balance()); | ||
// tag::wallet[] | ||
|
@@ -58,8 +54,8 @@ public Effect<String> deposit(@PathVariable int amount) { | |
} | ||
|
||
@GetMapping // <4> | ||
public Effect<Balance> get() { | ||
return effects().reply(new Balance(currentState().balance())); | ||
public Effect<Integer> get() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to return a complex type. I think that returning Interge will have a similar effect as returning a String (see #1686). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Although, I don't think an Integer would compose as a String but I don't know how to test it. How did you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, it will just be a raw number being returned with content type json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. We agree then 👍 |
||
return effects().reply(currentState().balance()); | ||
} | ||
} | ||
// end::wallet[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, why not, just please add similar changes to
java-spring-transfer-workflow-compensation