ddd-by-examples / all-things-cqrs

Comprehensive guide to a couple of possible ways of synchronizing two states with Spring tools. Synchronization is shown by separating command and queries in a simple CQRS application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add possibility to view current limit

vincent-fuchs opened this issue · comments

Hi,

Viewing the list of withdrawals is good, but one interesting thing would be to also show how to sync and retrieve the credit card limit.

For instance, I feel it's not very clear why we do this :

we modify the limit but it doesn't have any impact, does it ? when I comment the line, the test is still passing.

If we were to provide a GET endpoint to view the card limit, it would show how to read all withdraw events from the store to build an up to date view of the credit card.

Hi!

The code you pasted is for keeping the invariants of the aggregate in place. It validates if the command should be accepted or denied.

That is why test for synchronizing command and queries is still passing when you comment this line. But this test does not pass:

 @Test
    public void shouldBeAbleToWithdrawMoney() {
        //given
        CreditCard creditCard = new CreditCard(TEN);

        //when
        creditCard.withdraw(ONE);

        //expect
        assertThat(creditCard.availableBalance()).isEqualByComparingTo(new BigDecimal(9));
        assertThat(creditCard.getWithdrawals()).hasSize(1);
        assertThat(creditCard.getWithdrawals().get(0).getAmount()).isEqualByComparingTo(ONE);
    }

Although it would be interesting to see rebuilidng the state from commands - this is not primary goal of this project. In Event Sourcing we build internal projection for validating commands. In our CQRS project we build projection for commands (by keeping state) and projection for reads (by keeping state).

Plus there is one module coming soon that uses event sourcing :) so your issue might get addressed

Thanks and keep posting!