Skip to content

Commit

Permalink
refactor: or-2334 make distinction between messages and commands
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy committed Dec 11, 2024
1 parent 168869f commit bf6b656
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ItemGroup>
<Folder Include="GrarConsumer\Handlers\Fusies\" />
<Folder Include="Infrastructure\ConfigurationBindings\" />
<Folder Include="MessageHandling\Postgres\" />
<Folder Include="Verenigingen\Contactgegevens\FeitelijkeVereniging\" />
<Folder Include="Verenigingen\Vertegenwoordigers\FeitelijkeVereniging\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Acties.GrarConsumer;
using Amazon.Runtime;
using Dubbels;
using EventStore;
using Grar.AddressMatch;
using Hosts.Configuration;
Expand All @@ -13,6 +12,8 @@
using Wolverine.AmazonSqs;
using Wolverine.ErrorHandling;
using Wolverine.Postgresql;
using VoegDubbelToeMessage = Messages.VoegDubbelToeMessage;
using VoegDubbelToeMessageHandler = MessageHandling.Postgres.Dubbels.VoegDubbelToeMessageHandler;

public static class WolverineExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.ResponseWriter;

using AssociationRegistry.Admin.Api.Infrastructure.Extensions;
using Extensions;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.Sequence;

using AssociationRegistry.Admin.Api.Infrastructure.Extensions;
using AssociationRegistry.Admin.Schema.Detail;
using AssociationRegistry.EventStore;
using Extensions;
using Schema.Detail;
using EventStore;
using Marten;

public class SequenceGuarder : ISequenceGuarder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.Validation;

using AssociationRegistry.Admin.Api.Infrastructure.ExceptionHandlers;
using ExceptionHandlers;
using FluentValidation;
using System.Diagnostics.CodeAnalysis;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace AssociationRegistry.Admin.Api.MessageHandling.Postgres.Dubbels;

using Messages;
using Wolverine;

public class VoegDubbelToeMessageHandler(IMessageBus messageBus)
{
public async Task Handle(VoegDubbelToeMessage message, CancellationToken cancellationToken)
{
var command = message.ToCommand();

await messageBus.InvokeAsync(command, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
namespace AssociationRegistry.Admin.Api.Verenigingen.Registreer.MetRechtspersoonlijkheid.RequestModels;

using AssociationRegistry.Admin.Api.Infrastructure.Validation;
using Infrastructure.Validation;
using FluentValidation;

public class RegistreerVerenigingUitKboRequestValidator : AbstractValidator<RegistreerVerenigingUitKboRequest>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Acties.MarkeerAlsDubbelVan;

using Dubbels;
using Framework;
using Marten;
using Messages;
using Vereniging;
using Vereniging.Exceptions;
using Wolverine.Marten;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace AssociationRegistry.Acties.VoegDubbelToe;

using Vereniging;

public record VoegDubbelToeCommand(VCode VCode, VCode VCodeDubbeleVereniging);
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace AssociationRegistry.Dubbels;
namespace AssociationRegistry.Acties.VoegDubbelToe;

using AssociationRegistry.EventStore;
using AssociationRegistry.Framework;
using NodaTime;
using EventStore;
using Framework;
using Vereniging;
using NodaTime;

public class VoegDubbelToeMessageHandler(IVerenigingsRepository repository)
public class VoegDubbelToeCommandHandler(IVerenigingsRepository repository)
{
public async Task Handle(VoegDubbelToeMessage message, CancellationToken cancellationToken)
public async Task Handle(VoegDubbelToeCommand command, CancellationToken cancellationToken)
{
var vereniging = await repository.Load<Vereniging>(message.VCode);
var vereniging = await repository.Load<Vereniging>(command.VCode);

vereniging.VoegDubbeleVerenigingToe(message.VCodeDubbeleVereniging);
vereniging.VoegDubbeleVerenigingToe(command.VCodeDubbeleVereniging);

await repository.Save(
vereniging,
Expand Down
5 changes: 0 additions & 5 deletions src/AssociationRegistry/Dubbels/VoegDubbelToeMessage.cs

This file was deleted.

10 changes: 10 additions & 0 deletions src/AssociationRegistry/Messages/VoegDubbelToeMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AssociationRegistry.Messages;

using AssociationRegistry.Acties.VoegDubbelToe;
using AssociationRegistry.Vereniging;

public record VoegDubbelToeMessage(VCode VCode, VCode VCodeDubbeleVereniging)
{
public VoegDubbelToeCommand ToCommand()
=> new(VCode, VCodeDubbeleVereniging);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ namespace AssociationRegistry.Test.Admin.Api.Commands.FeitelijkeVereniging.When_
using Common.AutoFixture;
using Common.Framework;
using Common.Scenarios.CommandHandling;
using Dubbels;
using Events;
using FluentAssertions;
using GrarConsumer.FusieEvents.When_Consuming_Merger_Events;
using Marten;
using Messages;
using Moq;
using Vereniging;
using Wolverine;
using Wolverine.Marten;
using Xunit;
using Xunit.Categories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace AssociationRegistry.Test.WhenVoegDubbelToe;

using Acties.VoegDubbelToe;
using AutoFixture;
using Common.AutoFixture;
using Common.Framework;
using Common.Scenarios.CommandHandling;
using Dubbels;
using Vereniging;
using Vereniging.Exceptions;
using Xunit;
Expand All @@ -18,14 +18,14 @@ public async Task Then_Throws_InvalidOperationVerenigingKanGeenDubbelWordenVanZi
var scenario = new FeitelijkeVerenigingWerdGeregistreerdScenario();
var repositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState());
var vCode = fixture.Create<VCode>();
var message = fixture.Create<VoegDubbelToeMessage>() with
var command = fixture.Create<VoegDubbelToeCommand>() with
{
VCode = scenario.VCode,
VCodeDubbeleVereniging = scenario.VCode,
};
var sut = new VoegDubbelToeMessageHandler(repositoryMock);
var sut = new VoegDubbelToeCommandHandler(repositoryMock);

await Assert.ThrowsAsync<InvalidOperationVerenigingKanGeenDubbelWordenVanZichzelf>(
async () => await sut.Handle(message, CancellationToken.None));
async () => await sut.Handle(command, CancellationToken.None));
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
namespace AssociationRegistry.Test.WhenVoegDubbelToe;

using Acties.VoegDubbelToe;
using AutoFixture;
using Common.AutoFixture;
using Common.Framework;
using Common.Scenarios.CommandHandling;
using Dubbels;
using Events;
using Xunit;

public class Given_Valid_VoegDubbelToeMessage
public class Given_Valid_VoegDubbelToeCommand
{
[Fact]
public async Task Then_Throws_InvalidOperationVerenigingKanGeenDubbelWordenVanZichzelf()
{
var fixture = new Fixture().CustomizeDomain();
var scenario = new FeitelijkeVerenigingWerdGeregistreerdScenario();
var repositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState());
var message = fixture.Create<VoegDubbelToeMessage>()
var command = fixture.Create<VoegDubbelToeCommand>()
with
{
VCode = scenario.VCode,
};
var sut = new VoegDubbelToeMessageHandler(repositoryMock);
var sut = new VoegDubbelToeCommandHandler(repositoryMock);

await sut.Handle(message, CancellationToken.None);
await sut.Handle(command, CancellationToken.None);

repositoryMock.ShouldHaveSaved(new VerenigingWerdToegevoegdAlsDubbel(scenario.VCode, message.VCodeDubbeleVereniging));
repositoryMock.ShouldHaveSaved(new VerenigingWerdToegevoegdAlsDubbel(scenario.VCode, command.VCodeDubbeleVereniging));
}
}

0 comments on commit bf6b656

Please sign in to comment.