Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageVersion Include="EntityFrameworkCore.Exceptions.Common" Version="10.0.1" />
<PackageVersion Include="EntityFrameworkCore.Exceptions.SqlServer" Version="10.0.1" />
<PackageVersion Include="EventStoreProjections" Version="2023.12.3" />
<PackageVersion Include="FileProcessor.File.DomainEvents" Version="2026.9.2.153" />
<PackageVersion Include="FileProcessor.File.DomainEvents" Version="2026.9.2.157" />
<PackageVersion Include="FileProcessor.FileImportLog.DomainEvents" Version="2026.9.2.153" />
<PackageVersion Include="HealthMonitoring.Client" Version="2026.9.2.30" />
<PackageVersion Include="Lamar" Version="16.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private Task<Result> HandleFileDomainEvent(IDomainEvent domainEvent,
FileProcessor.File.DomainEvents.FileLineProcessingSuccessfulEvent de => this.EstateReportingRepository.UpdateFileLine(de, cancellationToken),
FileProcessor.File.DomainEvents.FileLineProcessingFailedEvent de => this.EstateReportingRepository.UpdateFileLine(de, cancellationToken),
FileProcessor.File.DomainEvents.FileLineProcessingIgnoredEvent de => this.EstateReportingRepository.UpdateFileLine(de, cancellationToken),
FileProcessor.File.DomainEvents.FileLineTransactionDispatchFailedEvent de => this.EstateReportingRepository.UpdateFileLine(de, cancellationToken),
FileProcessor.File.DomainEvents.FileProcessingCompletedEvent de => this.EstateReportingRepository.UpdateFileAsComplete(de, cancellationToken),
_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ Task<Result> UpdateFileAsComplete(FileProcessingCompletedEvent domainEvent,

Task<Result> UpdateFileLine(FileLineProcessingSuccessfulEvent domainEvent,
CancellationToken cancellationToken);

Task<Result> UpdateFileLine(FileLineTransactionDispatchFailedEvent domainEvent,
CancellationToken cancellationToken);

Task<Result> UpdateFileLine(FileLineProcessingFailedEvent domainEvent,
CancellationToken cancellationToken);
Expand Down Expand Up @@ -2052,6 +2055,19 @@ public async Task<Result> UpdateFileLine(FileLineProcessingSuccessfulEvent domai
cancellationToken);
}

public async Task<Result> UpdateFileLine(FileLineTransactionDispatchFailedEvent domainEvent,
CancellationToken cancellationToken) {
using ResolvedDbContext<EstateManagementContext>? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, domainEvent.EstateId.ToString());
await using EstateManagementContext context = resolvedContext.Context;

return await this.UpdateFileLineStatus(context,
domainEvent.FileId,
domainEvent.LineNumber,
Guid.Empty,
"D",
cancellationToken);
}

private async Task<Result> UpdateFileLineStatus(EstateManagementContext context,
Guid fileId,
Int32 lineNumber,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Imposter.Abstractions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
Expand Down Expand Up @@ -32,9 +33,9 @@ public async Task PostEventAsync_WhenAllHandlersSucceed_ReturnsOk()
domainEvent,
new ResultDomainEventHandler(Result.Success()));

IActionResult result = await controller.PostEventAsync(domainEvent, CancellationToken.None);

result.ShouldBeOfType<OkResult>();
IResult result = await controller.PostEventAsync(domainEvent, CancellationToken.None);
result.ShouldBeOfType<Ok>();
}

[Fact]
Expand All @@ -44,9 +45,9 @@ public async Task PostEventAsync_WhenNoHandlersAreConfigured_ReturnsOk()
DomainEvent domainEvent = CreateDomainEvent();
DomainEventController controller = CreateController(domainEvent);

IActionResult result = await controller.PostEventAsync(domainEvent, CancellationToken.None);
IResult result = await controller.PostEventAsync(domainEvent, CancellationToken.None);

result.ShouldBeOfType<OkResult>();
result.ShouldBeOfType<Ok>();
}

[Fact]
Expand All @@ -58,10 +59,10 @@ public async Task PostEventAsync_WhenHandlerReturnsFailure_ReturnsDetailedProble

DomainEventController controller = CreateController(domainEvent, handler);

ObjectResult result = (ObjectResult)await controller.PostEventAsync(domainEvent, CancellationToken.None);
ProblemHttpResult result = (ProblemHttpResult)await controller.PostEventAsync(domainEvent, CancellationToken.None);

result.StatusCode.ShouldBe(500);
ProblemDetails problemDetails = (ProblemDetails)result.Value;
var problemDetails = result.ProblemDetails;
problemDetails.Title.ShouldBe("One or more event handlers failed");
problemDetails.Status.ShouldBe(500);
problemDetails.Extensions["eventId"].ShouldBeOfType<Guid>();
Expand All @@ -82,9 +83,9 @@ public async Task PostEventAsync_WhenMultipleHandlersFail_ReturnsEveryFailure()
new ResultDomainEventHandler(Result.Failure("First failure")),
new ThrowingDomainEventHandler("Second failure"));

ObjectResult result = (ObjectResult)await controller.PostEventAsync(domainEvent, CancellationToken.None);
ProblemHttpResult result = (ProblemHttpResult)await controller.PostEventAsync(domainEvent, CancellationToken.None);

String failuresJson = System.Text.Json.JsonSerializer.Serialize(((ProblemDetails)result.Value).Extensions["failures"]);
String failuresJson = System.Text.Json.JsonSerializer.Serialize(result.ProblemDetails.Extensions["failures"]);
result.StatusCode.ShouldBe(500);
failuresJson.ShouldContain("First failure");
failuresJson.ShouldContain("Second failure");
Expand Down
41 changes: 31 additions & 10 deletions TransactionProcessor/Controllers/DomainEventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Shared.Exceptions;
using Shared.Results;
using Shared.Results.Web;

namespace TransactionProcessor.Controllers
{
Expand Down Expand Up @@ -55,10 +59,15 @@ public DomainEventController(IDomainEventHandlerResolver domainEventHandlerResol
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> PostEventAsync([FromBody] Object request,
public async Task<IResult> PostEventAsync([FromBody] Object request,
CancellationToken cancellationToken)
{
IDomainEvent domainEvent = await this.GetDomainEvent(request);
Result<IDomainEvent> domainEventResult = await this.GetDomainEvent(request);

if (domainEventResult.IsFailed)
return ResponseFactory.FromResult(domainEventResult, SuccessFactory);

IDomainEvent domainEvent = domainEventResult.Data;

List<IDomainEventHandler> eventHandlers = this.GetDomainEventHandlers(domainEvent);

Expand All @@ -72,7 +81,7 @@ public async Task<IActionResult> PostEventAsync([FromBody] Object request,
{
// Log a warning out
Logger.LogInformation($"No event handlers configured for Event Type [{domainEvent.GetType().Name}]");
return this.Ok();
return Results.Ok();
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved
}

List<HandlerExecution> executions = eventHandlers
Expand All @@ -91,7 +100,7 @@ public async Task<IActionResult> PostEventAsync([FromBody] Object request,
List<HandlerFailure> failures = executions.SelectMany(this.GetFailures).ToList();
if (failures.Any())
{
return this.Problem(title: "One or more event handlers failed",
return Results.Problem(title: "One or more event handlers failed",
statusCode: 500,
extensions: new Dictionary<String, Object>
{
Expand All @@ -102,8 +111,8 @@ public async Task<IActionResult> PostEventAsync([FromBody] Object request,
}

Logger.LogWarning($"Finished processing event - ID [{domainEvent.EventId}]");
return this.Ok();

return Results.Ok();
}
catch (Exception ex)
{
Expand All @@ -114,6 +123,10 @@ public async Task<IActionResult> PostEventAsync([FromBody] Object request,
}
}

private IDomainEvent SuccessFactory(IDomainEvent arg) {
return arg;
}

private void Callback(CancellationToken cancellationToken,
Guid eventId)
{
Expand Down Expand Up @@ -177,21 +190,29 @@ private List<IDomainEventHandler> GetDomainEventHandlers(IDomainEvent domainEven
return eventHandlersResult.Data;
}

private async Task<IDomainEvent> GetDomainEvent(Object domainEvent)
private async Task<Result<IDomainEvent>> GetDomainEvent(Object domainEvent)
{
String eventType = this.Request.Headers["eventType"].ToString();

Type type = TypeMap.GetType(eventType);
Type type;

try {
type = TypeMap.GetType(eventType);
}
catch (Exception ex) {
// Just swallowing exception here...
type = null;
}

if (type == null)
throw new NotFoundException($"Failed to find a domain event with type {eventType}");
return Result.NotFound($"Failed to find a domain event with type {eventType}");

if (type.IsSubclassOf(typeof(DomainEvent)))
{
String json = StringSerialiser.Serialise(domainEvent);

DomainEventFactory domainEventFactory = new();
return domainEventFactory.CreateDomainEvent(json, type);
return Result.Success(domainEventFactory.CreateDomainEvent(json, type) as IDomainEvent);
}

return null;
Expand Down
3 changes: 2 additions & 1 deletion TransactionProcessor/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"FileProcessingCompletedEvent",
"MerchantOpeningHoursUpdatedEvent",
"MerchantScheduleCreatedEvent",
"MerchantScheduleMonthUpdatedEvent"
"MerchantScheduleMonthUpdatedEvent",
"FileLineTransactionDispatchFailedEvent"
]
},
"EventHandlerConfigurationDomain": {
Expand Down
Loading