Remove extraneous account fetch in POST /v1/donation/redeem-receipt

This commit is contained in:
Chris Eager 2025-04-15 13:44:28 -05:00 committed by Chris Eager
parent 57be4d798b
commit 7cac6f6f72
1 changed files with 6 additions and 8 deletions

View File

@ -104,14 +104,12 @@ public class DonationController {
.type(MediaType.TEXT_PLAIN_TYPE).build()); .type(MediaType.TEXT_PLAIN_TYPE).build());
} }
return accountsManager.getByAccountIdentifierAsync(auth.getAccount().getUuid()) return accountsManager.updateAsync(auth.getAccount(), a -> {
.thenCompose(optionalAccount ->
optionalAccount.map(account -> accountsManager.updateAsync(account, a -> {
a.addBadge(clock, new AccountBadge(badgeId, receiptExpiration, request.isVisible())); a.addBadge(clock, new AccountBadge(badgeId, receiptExpiration, request.isVisible()));
if (request.isPrimary()) { if (request.isPrimary()) {
a.makeBadgePrimaryIfExists(clock, badgeId); a.makeBadgePrimaryIfExists(clock, badgeId);
} }
})).orElse(CompletableFuture.completedFuture(null))) })
.thenApply(ignored -> Response.ok().build()); .thenApply(ignored -> Response.ok().build());
}); });
}).thenCompose(Function.identity()); }).thenCompose(Function.identity());