mirror of
https://github.com/wahyd4/cash-code-test.git
synced 2026-08-09 21:36:08 +10:00
19 lines
447 B
Go
19 lines
447 B
Go
package commands
|
|
|
|
import "github.com/wahyd4/cash/domains"
|
|
|
|
// WithdrawCommand the command for withdrawing some money
|
|
type WithdrawCommand struct {
|
|
Account string
|
|
Money float64
|
|
}
|
|
|
|
// Run withdraws money from the bank, returns error if fails
|
|
func (command *WithdrawCommand) Run(bank *domains.Bank) error {
|
|
account, err := bank.AccountFromName(command.Account)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return bank.WithdrawFor(account, command.Money)
|
|
}
|