Beispiel #1
0
  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();
  }
Beispiel #2
0
  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();
  }