Commands

In order to make changes to our system we will need commands. Let's start with a few commands that match up closely to the events that we have already written.

struct DepositMoney {
    amount: f64
}

struct WithdrawMoney {
    amount: f64
}

struct WriteCheck {
    check_number: u32,
    amount: f64
}

These will all need to implement the cqrs_es::Command<BankAccount,BankAccountEvent> trait. The handle method of this trait is where our business logic will go, for now we will leave that out and just return an empty vector.

impl Command<BankAccount, BankAccountEvent> for DepositMoney {
    fn handle(self, account: &BankAccount) -> Result<Vec<BankAccountEvent>, AggregateError> {
        Ok(vec![])
    }
}

impl Command<BankAccount, BankAccountEvent> for WithdrawMoney {
    fn handle(self, account: &BankAccount) -> Result<Vec<BankAccountEvent>, AggregateError> {
        Ok(vec![])
    }
}

impl Command<BankAccount, BankAccountEvent> for WriteCheck {
    fn handle(self, account: &BankAccount) -> Result<Vec<BankAccountEvent>, AggregateError> {
        Ok(vec![])
    }
}

We now have all the components in place to begin adding our tests.