Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: or-2596 make sure gemeentenaam serializes only to its value #1016

Merged
merged 1 commit into from
Dec 4, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace AssociationRegistry.Acties.GrarConsumer.HeradresseerLocaties;

using Grar.GrarUpdates.Hernummering;
using Grar.GrarUpdates.LocatieFinder;
using JasperFx.Core.Reflection;

public class HeradresseerLocatiesMessageFactory
{
private readonly LocatiesPerVCodeCollection _locatiesPerVCode;

private HeradresseerLocatiesMessageFactory(LocatiesPerVCodeCollection locatiesPerVCode)
{
_locatiesPerVCode = locatiesPerVCode;
}

public static HeradresseerLocatiesMessageFactory VoorLocaties(LocatiesPerVCodeCollection locatiesPerVCode)
=> new(locatiesPerVCode);

public IReadOnlyCollection<HeradresseerLocatiesMessage> MetNaarAdres(int destinationAdresId, string idempotencyKey)
{
return _locatiesPerVCode.Select(x => new HeradresseerLocatiesMessage(
x.VCode,
x.Locaties.Select(locatie => new TeHeradresserenLocatie(locatie.LocatieId, destinationAdresId.ToString()))
.ToList(),
idempotencyKey)).ToList().AsReadOnly();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
public static Postnamen FromValues(params string[] values)
=> new(values.Select(Postnaam.FromValue).ToList());

public static Postnamen Empty => new ([]);

Check warning on line 34 in src/AssociationRegistry/Grar/Models/PostalInfo/PostalInformationResponse.cs

View workflow job for this annotation

GitHub Actions / analyze-code

'Postnamen.Empty' hides inherited member 'ReadOnlyCollection<Postnaam>.Empty'. Use the new keyword if hiding was intended.

Check warning on line 34 in src/AssociationRegistry/Grar/Models/PostalInfo/PostalInformationResponse.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Admin.AddressSync)

'Postnamen.Empty' hides inherited member 'ReadOnlyCollection<Postnaam>.Empty'. Use the new keyword if hiding was intended.
}

public record Postnaam
{
public string Value { get; init; }

private Postnaam(string Value)
{
this.Value = Value;
}

public static Postnaam FromGrar(Models.Postnaam postnaam)
=> new(postnaam.GeografischeNaam.Spelling);

public static Postnaam FromValue(string postnaam)
{
if (string.IsNullOrEmpty(postnaam))
Expand All @@ -54,7 +57,8 @@
public static implicit operator string(Postnaam postnaam)
=> postnaam.Value;

public string Value { get; init; }
public override string ToString()
=> Value;

public void Deconstruct(out string Value)
{
Expand Down
9 changes: 0 additions & 9 deletions src/AssociationRegistry/Vereniging/Locaties/Adres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,3 @@ public static Adres Hydrate(Registratiedata.AdresUitAdressenregister adres)
adres.Gemeente,
België);
}

public record Gemeentenaam(string Naam)
{
public static Gemeentenaam Hydrate(string gemeente)
=> new(gemeente);

public static Gemeentenaam FromVerrijkteGemeentenaam(VerrijkteGemeentenaam gemeentenaam)
=> new(gemeentenaam.Format());
}
15 changes: 15 additions & 0 deletions src/AssociationRegistry/Vereniging/Locaties/Gemeentenaam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace AssociationRegistry.Vereniging;

using Events;

public record Gemeentenaam(string Naam)
{
public static Gemeentenaam Hydrate(string gemeente)
=> new(gemeente);

public static Gemeentenaam FromVerrijkteGemeentenaam(VerrijkteGemeentenaam gemeentenaam)
=> new(gemeentenaam.Format());

public override string ToString()
=> Naam;
}
8 changes: 5 additions & 3 deletions src/AssociationRegistry/Vereniging/VerenigingOfAnyKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,11 @@ private IEvent GetAdresMatchExceptionEvent(
{
IEvent @event = ex.StatusCode switch
{
//TODO: is this correct?
HttpStatusCode.NotFound => AdresWerdNietGevondenInAdressenregister.From(VCode, locatieVoorTeMatchenAdres),
_ => new AdresKonNietOvergenomenWordenUitAdressenregister(VCode, locatieId, locatieVoorTeMatchenAdres.Adres.ToAdresString(),
HttpStatusCode.NotFound =>
AdresWerdNietGevondenInAdressenregister.From(VCode, locatieVoorTeMatchenAdres),

_ =>
new AdresKonNietOvergenomenWordenUitAdressenregister(VCode, locatieId, locatieVoorTeMatchenAdres.Adres.ToAdresString(),
GetExceptionMessage(ex.StatusCode)),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Framework.Customizations;
using Grar;
using Grar.Exceptions;
using Grar.Models;
using Moq;
using Resources;
using System.Net;
Expand Down Expand Up @@ -40,12 +41,21 @@ public async Task Then_AdresKonNietOvergenomenWordenUitAdressenregister()
new VerenigingState()
.Apply(feitelijkeVerenigingWerdGeregistreerd));

await vereniging.ProbeerAdresTeMatchen(grarClient.Object, feitelijkeVerenigingWerdGeregistreerd.Locaties.First().LocatieId,
var locatie = feitelijkeVerenigingWerdGeregistreerd.Locaties.First();

await vereniging.ProbeerAdresTeMatchen(grarClient.Object, locatie.LocatieId,
CancellationToken.None);

var @event = vereniging.UncommittedEvents.OfType<AdresKonNietOvergenomenWordenUitAdressenregister>().SingleOrDefault();

@event.Should().NotBeNull();

@event.Adres.Should().BeEquivalentTo($"{locatie.Adres.Straatnaam} {locatie.Adres.Huisnummer}" +
(!string.IsNullOrWhiteSpace(locatie.Adres.Busnummer)
? $" bus {locatie.Adres.Busnummer}"
: string.Empty) +
$", {locatie.Adres.Postcode} {locatie.Adres.Gemeente}, {locatie.Adres.Land}");

@event!.Reden.Should().Be(ExceptionMessages.AdresKonNietOvergenomenWordenBadRequest);
}
}
Loading