Skip to content

Commit

Permalink
fix: add logging for realizeunplannedbuildingunit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Mar 27, 2024
1 parent 38870f6 commit 2783f12
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Handlers.Building
using BuildingRegistry.Building.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Requests.Building;
using TicketingService.Abstractions;

Expand All @@ -27,6 +28,7 @@ public sealed class RealizeAndMeasureUnplannedBuildingLambdaHandler : BuildingLa
private readonly IPersistentLocalIdGenerator _persistentLocalIdGenerator;
private readonly ILifetimeScope _lifetimeScope;
private readonly bool _toggleAutomaticBuildingUnitCreationEnabled;
private ILogger<RealizeAndMeasureUnplannedBuildingLambdaHandler> _logger;

public RealizeAndMeasureUnplannedBuildingLambdaHandler(
IConfiguration configuration,
Expand All @@ -38,7 +40,8 @@ public RealizeAndMeasureUnplannedBuildingLambdaHandler(
IAddresses addresses,
BackOfficeContext backOfficeContext,
IPersistentLocalIdGenerator persistentLocalIdGenerator,
ILifetimeScope lifetimeScope)
ILifetimeScope lifetimeScope,
ILoggerFactory loggerFactory)
: base(
configuration,
retryPolicy,
Expand All @@ -52,6 +55,7 @@ public RealizeAndMeasureUnplannedBuildingLambdaHandler(
_persistentLocalIdGenerator = persistentLocalIdGenerator;
_lifetimeScope = lifetimeScope;
_toggleAutomaticBuildingUnitCreationEnabled = configuration.GetValue<bool>("AutomaticBuildingUnitCreationToggle", false);
_logger = loggerFactory.CreateLogger<RealizeAndMeasureUnplannedBuildingLambdaHandler>();
}

protected override async Task<object> InnerHandle(RealizeAndMeasureUnplannedBuildingLambdaRequest request,
Expand Down Expand Up @@ -81,6 +85,7 @@ await IdempotentCommandHandler.Dispatch(

private async Task RealizeUnplannedBuildingUnit(RealizeAndMeasureUnplannedBuildingLambdaRequest request, CancellationToken cancellationToken)
{
_logger.LogInformation("RealizeUnplannedBuildingUnit started.");
if (request.Request.GrbData.GrbObjectType != MainBuildingGrbObjectType)
{
return;
Expand All @@ -93,12 +98,15 @@ private async Task RealizeUnplannedBuildingUnit(RealizeAndMeasureUnplannedBuildi
.SelectMany(x => x.Addresses)
.ToList();

_logger.LogInformation($"Found {addresses.Count} addresses.");

var activeAddresses = addresses.Any()
? await GetActiveAddresses(addresses)
: new List<AddressData>();

if (activeAddresses.Count != 1)
{
_logger.LogInformation($"Found more than one active address");
return;
}

Expand All @@ -111,6 +119,7 @@ private async Task RealizeUnplannedBuildingUnit(RealizeAndMeasureUnplannedBuildi

if (buildingUnitAddressRelations.Any())
{
_logger.LogInformation("Address already has a building unit.");
return;
}

Expand All @@ -124,6 +133,7 @@ private async Task RealizeUnplannedBuildingUnit(RealizeAndMeasureUnplannedBuildi

try
{
_logger.LogInformation("Dispatching RealizeUnplannedBuildingUnit command.");
await using var scope = _lifetimeScope.BeginLifetimeScope();
await scope.Resolve<IIdempotentCommandHandler>().Dispatch(
buildingUnitCommand.CreateCommandId(),
Expand Down

0 comments on commit 2783f12

Please sign in to comment.