Skip to content

Commit 09d226d

Browse files
Events added for #31 - money transfer example
1 parent c01d5cc commit 09d226d

File tree

8 files changed

+184
-0
lines changed

8 files changed

+184
-0
lines changed

examples/bank-account/RetailBank.AzureFunctionApp/RetailBank.AzureFunctionApp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@
5656
<Private>true</Private>
5757
</ProjectReference>
5858
</ItemGroup>
59+
<ItemGroup>
60+
<Folder Include="Transfer\Functions\" />
61+
<Folder Include="Transfer\Projections\" />
62+
</ItemGroup>
5963
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
3+
namespace RetailBank.AzureFunctionApp.Transfer.Events
4+
{
5+
6+
[EventName("Refund Failed")]
7+
public sealed class RefundFailed
8+
{
9+
10+
public string Reason { get; set; }
11+
12+
/// <summary>
13+
/// Additional commentary on the refund failure
14+
/// </summary>
15+
public string Commentary { get; set; }
16+
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
3+
namespace RetailBank.AzureFunctionApp.Transfer.Events
4+
{
5+
[EventName("Refund Initiated")]
6+
public sealed class RefundInitiated
7+
{
8+
9+
/// <summary>
10+
/// The amount to refund to the source
11+
/// </summary>
12+
/// <remarks>
13+
/// This may not be the same as the original transfer
14+
/// request if there were non-refundable charges etc
15+
/// </remarks>
16+
public decimal AmountToRefund { get; set; }
17+
18+
/// <summary>
19+
/// The reason that this refund was initiated
20+
/// </summary>
21+
public string Reason { get; set; }
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
3+
namespace RetailBank.AzureFunctionApp.Transfer.Events
4+
{
5+
[EventName("Source Funds Refunded")]
6+
public sealed class SourceFundsRefunded
7+
{
8+
9+
/// <summary>
10+
/// The amount refunded to the source account
11+
/// </summary>
12+
public decimal AmountRefunded { get; set; }
13+
14+
/// <summary>
15+
/// For an internal source, the sequence number as at which the refund was performed
16+
/// (Will be zero for an external account as this has no meaning for data we do not control)
17+
/// </summary>
18+
public int AsOfSequenceNumber { get; set; }
19+
20+
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace RetailBank.AzureFunctionApp.Transfer.Events
7+
{
8+
9+
/// <summary>
10+
/// Funds for this transfer were withdrawn from the source account
11+
/// </summary>
12+
[EventName("Source Funds Withdrawn")]
13+
public sealed class SourceFundsWithdrawn
14+
{
15+
16+
/// <summary>
17+
/// The amount withdrawn fro the source account
18+
/// </summary>
19+
/// <remarks>
20+
/// This may be different to the requested transfer if the transfer process
21+
/// allows for partial transfers
22+
/// </remarks>
23+
public decimal AmountWithdrawn { get; set; }
24+
25+
/// <summary>
26+
/// For an internal source, the sequence number as at which the withdrawal was performed
27+
/// (Will be zero for an external account as this has no meaning for data we do not control)
28+
/// </summary>
29+
public int AsOfSequenceNumber { get; set; }
30+
31+
/// <summary>
32+
/// Additional commentary on the funds withdrawal
33+
/// </summary>
34+
public string Commentary { get; set; }
35+
}
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace RetailBank.AzureFunctionApp.Transfer.Events
7+
{
8+
[EventName("Target Funds Deposited")]
9+
public sealed class TargetFundsDeposited
10+
{
11+
12+
/// <summary>
13+
/// The amount deposited in the target account
14+
/// </summary>
15+
/// <remarks>
16+
/// This may be different to the requested transfer if the transfer process
17+
/// allows for partial transfers
18+
/// </remarks>
19+
public decimal AmountDeposited { get; set; }
20+
21+
/// <summary>
22+
/// For an internal source, the sequence number as at which the deposit was performed
23+
/// (Will be zero for an external account as this has no meaning for data we do not control)
24+
/// </summary>
25+
public int AsOfSequenceNumber { get; set; }
26+
27+
/// <summary>
28+
/// Additional commentary on the funds deposit
29+
/// </summary>
30+
public string Commentary { get; set; }
31+
}
32+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using EventSourcingOnAzureFunctions.Common.EventSourcing;
2+
3+
namespace RetailBank.AzureFunctionApp.Transfer.Events
4+
{
5+
/// <summary>
6+
/// A money transfer between the source and target accounts has been initiated
7+
/// </summary>
8+
[EventName("Money Transfer Initiated")]
9+
public sealed class TransferInitiated
10+
{
11+
12+
/// <summary>
13+
/// The amount being transfered
14+
/// </summary>
15+
/// <remarks>
16+
/// This is currently a "same currency" transfer - we may consider expanding the example
17+
/// to include FX rates at a later date
18+
/// </remarks>
19+
public decimal Amount { get; set; }
20+
21+
/// <summary>
22+
/// The account number the transfer is coming from
23+
/// </summary>
24+
public string SourceAccountNumber { get; set; }
25+
26+
/// <summary>
27+
/// True if the account we are transfering from is in our bank
28+
/// </summary>
29+
public bool SourceIsInternal { get; set; }
30+
31+
/// <summary>
32+
/// The account the transfer is going to
33+
/// </summary>
34+
public string TargetAccountNumber { get; set; }
35+
36+
/// <summary>
37+
/// True if the account we are transfering to is in our bank
38+
/// </summary>
39+
public bool TargetIsInternal { get; set; }
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Transfers
2+
=========
3+
4+
A transfer is a money movement between accounts.
5+
It is used to demonstrate the idea of saga-based actions as replacements for the traditional database concept of transactions.
6+
7+
A transfer can succeed or fail due to the conditions of source and target account (assuming both are "ours")
8+
and a failed transfer should set back the accounts to the state they were in before it.

0 commit comments

Comments
 (0)