Created
March 4, 2020 07:14
-
-
Save ayende/0eabfa54997a889b79044393b2771c76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task SendMoney(SendMoneyRequest req) | |
{ | |
var srcAccount = await _accountRepository.LoadAsync(req.SourceAccount); | |
var dstAccount = await _accountRepository.LoadAsync(req.DesinationAccount); | |
Guard.Null(srcAccount, "Source account must exists"); | |
Guard.Null(dstAccount, "Destination account must exists"); | |
var rules = _transferValidationRules.GetAll(); | |
foreach(var rule in rules) | |
{ | |
await rule.Validate(req); | |
} | |
srcAccount.TransferFunds(dstAccount, req.Amount); | |
} | |
public class MoneyTransferValidationRules : IMoneyTransferValidationRules | |
{ | |
public ValidateTransferRule GetAll() | |
{ | |
yield return new SourceAccountIsValid(); | |
yield return new SourceAccountHasFunds(); | |
yield return new SourceAccountDailyLimitNotExceed(); | |
// .. many more .. | |
yield return new DestinationAccountHasNoLiens(); | |
yield return new DestinationAccountMaxAmountNotExceeded(); | |
// .. and more ... | |
yield return new MoneyTransferIsNotFromDirtyBitcoins(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment