Skip to content

Commit 84ea2b8

Browse files
WIP
1 parent 457044c commit 84ea2b8

File tree

6 files changed

+165
-28
lines changed

6 files changed

+165
-28
lines changed

TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class TransactionDomainEventHandler : IDomainEventHandler
4242
/// </summary>
4343
private readonly ISecurityServiceClient SecurityServiceClient;
4444

45+
private readonly ITransactionReceiptBuilder TransactionReceiptBuilder;
46+
4547
/// <summary>
4648
/// The token response
4749
/// </summary>
@@ -57,21 +59,24 @@ public class TransactionDomainEventHandler : IDomainEventHandler
5759
#region Constructors
5860

5961
/// <summary>
60-
/// Initializes a new instance of the <see cref="TransactionDomainEventHandler"/> class.
62+
/// Initializes a new instance of the <see cref="TransactionDomainEventHandler" /> class.
6163
/// </summary>
6264
/// <param name="transactionAggregateManager">The transaction aggregate manager.</param>
6365
/// <param name="feeCalculationManager">The fee calculation manager.</param>
6466
/// <param name="estateClient">The estate client.</param>
6567
/// <param name="securityServiceClient">The security service client.</param>
68+
/// <param name="transactionReceiptBuilder">The transaction receipt builder.</param>
6669
public TransactionDomainEventHandler(ITransactionAggregateManager transactionAggregateManager,
6770
IFeeCalculationManager feeCalculationManager,
6871
IEstateClient estateClient,
69-
ISecurityServiceClient securityServiceClient)
72+
ISecurityServiceClient securityServiceClient,
73+
ITransactionReceiptBuilder transactionReceiptBuilder)
7074
{
7175
this.TransactionAggregateManager = transactionAggregateManager;
7276
this.FeeCalculationManager = feeCalculationManager;
7377
this.EstateClient = estateClient;
7478
this.SecurityServiceClient = securityServiceClient;
79+
this.TransactionReceiptBuilder = transactionReceiptBuilder;
7580
}
7681

7782
#endregion
@@ -179,6 +184,28 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do
179184
}
180185
}
181186

187+
private async Task HandleSpecificDomainEvent(CustomerEmailReceiptRequestedEvent domainEvent,
188+
CancellationToken cancellationToken)
189+
{
190+
TransactionAggregate transactionAggregate = await this.TransactionAggregateManager.GetAggregate(domainEvent.EstateId, domainEvent.TransactionId, cancellationToken);
191+
192+
// TODO: Add DTO method to aggregate
193+
// Determine the body of the email
194+
var receiptMessage = await this.TransactionReceiptBuilder.GetEmailReceiptMessage(new Transaction(), cancellationToken);
195+
196+
// Send the message
197+
await this.SendEmailMessage("Transaction Successful", receiptMessage, domainEvent.CustomerEmailAddress, cancellationToken);
198+
199+
}
200+
201+
private async Task SendEmailMessage(String subject,
202+
String body,
203+
String emailAddress,
204+
CancellationToken cancellationToken)
205+
{
206+
207+
}
208+
182209
#endregion
183210
}
184211
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title></title>
7+
</head>
8+
<body>
9+
10+
</body>
11+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TransactionProcessor.BusinessLogic.Services
6+
{
7+
using System.IO.Abstractions;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Models;
11+
12+
public interface ITransactionReceiptBuilder
13+
{
14+
Task<String> GetEmailReceiptMessage(Transaction transaction, CancellationToken cancellationToken);
15+
}
16+
17+
public class TransactionReceiptBuilder : ITransactionReceiptBuilder
18+
{
19+
private readonly IFileSystem FileSystem;
20+
21+
public TransactionReceiptBuilder(IFileSystem fileSystem)
22+
{
23+
this.FileSystem = fileSystem;
24+
}
25+
26+
public async Task<String> GetEmailReceiptMessage(Transaction transaction,
27+
CancellationToken cancellationToken)
28+
{
29+
var fileData = await this.FileSystem.File.ReadAllTextAsync($"\\Receipts\\Email\\{transaction.OperatorIdentifier}\\TransactionAuthorised.html", cancellationToken);
30+
31+
// TODO: We will do substitutions here
32+
33+
return fileData;
34+
}
35+
}
36+
37+
38+
}

TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageReference Include="Shared.DomainDrivenDesign" Version="0.0.15.7" />
1212
<PackageReference Include="Shared.EventStore" Version="0.0.15.7" />
1313
<PackageReference Include="MediatR" Version="8.0.2" />
14+
<PackageReference Include="System.IO.Abstractions" Version="12.2.1" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TransactionProcessor.Models
6+
{
7+
public class Transaction
8+
{
9+
public String OperatorIdentifier { get; set; }
10+
}
11+
}
Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,76 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace TransactionProcessor.Transaction.DomainEvents
1+
namespace TransactionProcessor.Transaction.DomainEvents
62
{
3+
using System;
74
using System.Diagnostics.CodeAnalysis;
85
using Newtonsoft.Json;
96
using Shared.DomainDrivenDesign.EventSourcing;
107

8+
/// <summary>
9+
///
10+
/// </summary>
11+
/// <seealso cref="Shared.DomainDrivenDesign.EventSourcing.DomainEvent" />
1112
public class CustomerEmailReceiptRequestedEvent : DomainEvent
1213
{
14+
#region Constructors
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="CustomerEmailReceiptRequestedEvent"/> class.
18+
/// </summary>
19+
[ExcludeFromCodeCoverage]
20+
public CustomerEmailReceiptRequestedEvent()
21+
{
22+
}
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="CustomerEmailReceiptRequestedEvent"/> class.
26+
/// </summary>
27+
/// <param name="aggregateId">The aggregate identifier.</param>
28+
/// <param name="eventId">The event identifier.</param>
29+
/// <param name="estateId">The estate identifier.</param>
30+
/// <param name="merchantId">The merchant identifier.</param>
31+
/// <param name="customerEmailAddress">The customer email address.</param>
32+
private CustomerEmailReceiptRequestedEvent(Guid aggregateId,
33+
Guid eventId,
34+
Guid estateId,
35+
Guid merchantId,
36+
String customerEmailAddress) : base(aggregateId, eventId)
37+
{
38+
this.TransactionId = aggregateId;
39+
this.EstateId = estateId;
40+
this.MerchantId = merchantId;
41+
this.CustomerEmailAddress = customerEmailAddress;
42+
}
43+
44+
#endregion
45+
46+
#region Properties
47+
48+
/// <summary>
49+
/// Gets the customer email address.
50+
/// </summary>
51+
/// <value>
52+
/// The customer email address.
53+
/// </value>
1354
[JsonProperty]
14-
public Guid EstateId { get; private set; }
55+
public String CustomerEmailAddress { get; private set; }
1556

57+
/// <summary>
58+
/// Gets the estate identifier.
59+
/// </summary>
60+
/// <value>
61+
/// The estate identifier.
62+
/// </value>
1663
[JsonProperty]
17-
public Guid MerchantId { get; private set; }
64+
public Guid EstateId { get; private set; }
1865

66+
/// <summary>
67+
/// Gets the merchant identifier.
68+
/// </summary>
69+
/// <value>
70+
/// The merchant identifier.
71+
/// </value>
1972
[JsonProperty]
20-
public String CustomerEmailAddress { get; private set; }
73+
public Guid MerchantId { get; private set; }
2174

2275
/// <summary>
2376
/// Gets the transaction identifier.
@@ -28,30 +81,26 @@ public class CustomerEmailReceiptRequestedEvent : DomainEvent
2881
[JsonProperty]
2982
public Guid TransactionId { get; private set; }
3083

31-
[ExcludeFromCodeCoverage]
32-
public CustomerEmailReceiptRequestedEvent()
33-
{
84+
#endregion
3485

35-
}
36-
37-
private CustomerEmailReceiptRequestedEvent(Guid aggregateId,
38-
Guid eventId,
39-
Guid estateId,
40-
Guid merchantId,
41-
String customerEmailAddress) : base(aggregateId, eventId)
42-
{
43-
this.TransactionId = aggregateId;
44-
this.EstateId = estateId;
45-
this.MerchantId = merchantId;
46-
this.CustomerEmailAddress = customerEmailAddress;
47-
}
86+
#region Methods
4887

88+
/// <summary>
89+
/// Creates the specified aggregate identifier.
90+
/// </summary>
91+
/// <param name="aggregateId">The aggregate identifier.</param>
92+
/// <param name="estateId">The estate identifier.</param>
93+
/// <param name="merchantId">The merchant identifier.</param>
94+
/// <param name="customerEmailAddress">The customer email address.</param>
95+
/// <returns></returns>
4996
public static CustomerEmailReceiptRequestedEvent Create(Guid aggregateId,
5097
Guid estateId,
5198
Guid merchantId,
5299
String customerEmailAddress)
53100
{
54-
return new CustomerEmailReceiptRequestedEvent(aggregateId,Guid.NewGuid(), estateId,merchantId, customerEmailAddress);
101+
return new CustomerEmailReceiptRequestedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, customerEmailAddress);
55102
}
103+
104+
#endregion
56105
}
57-
}
106+
}

0 commit comments

Comments
 (0)