void handlePatchForDeposit(Operation patch) { BankAccountServiceState currentState = getState(patch); BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class); currentState.balance += body.amount; setState(patch, currentState); patch.setBody(currentState); patch.complete(); }
void handlePatchForWithdraw(Operation patch) { BankAccountServiceState currentState = getState(patch); BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class); if (body.amount > currentState.balance) { patch.fail(new IllegalArgumentException("Not enough funds to withdraw")); return; } currentState.balance -= body.amount; setState(patch, currentState); patch.setBody(currentState); patch.complete(); }