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

feat: update postalnames #562

Merged
merged 2 commits into from
Jan 7, 2025
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
14 changes: 0 additions & 14 deletions PostalRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostalRegistry.Tests", "tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostalRegistry.Projections.Legacy", "src\PostalRegistry.Projections.Legacy\PostalRegistry.Projections.Legacy.csproj", "{0E08B66D-9320-47D8-980C-68753A0C0574}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostalRegistry.BPostReader", "src\PostalRegistry.BPostReader\PostalRegistry.BPostReader.csproj", "{13568DA1-586D-4AD0-8834-8DBADD95207C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostalRegistry.EventGenerator.CrabPostinfo", "src\PostalRegistry.EventGenerator.CrabPostinfo\PostalRegistry.EventGenerator.CrabPostinfo.csproj", "{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{50D64CB2-C9C2-4786-A350-DA4239162FBA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostalRegistry.Structurizr", "docs\PostalRegistry.Structurizr\PostalRegistry.Structurizr.csproj", "{73D40942-1B6E-4BCF-9F4F-332DEAC48A67}"
Expand Down Expand Up @@ -87,14 +83,6 @@ Global
{0E08B66D-9320-47D8-980C-68753A0C0574}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E08B66D-9320-47D8-980C-68753A0C0574}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E08B66D-9320-47D8-980C-68753A0C0574}.Release|Any CPU.Build.0 = Release|Any CPU
{13568DA1-586D-4AD0-8834-8DBADD95207C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13568DA1-586D-4AD0-8834-8DBADD95207C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13568DA1-586D-4AD0-8834-8DBADD95207C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13568DA1-586D-4AD0-8834-8DBADD95207C}.Release|Any CPU.Build.0 = Release|Any CPU
{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC}.Release|Any CPU.Build.0 = Release|Any CPU
{73D40942-1B6E-4BCF-9F4F-332DEAC48A67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73D40942-1B6E-4BCF-9F4F-332DEAC48A67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73D40942-1B6E-4BCF-9F4F-332DEAC48A67}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -145,8 +133,6 @@ Global
{488B07C6-FEDE-4F8D-A6E2-A7DFED79BBA1} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
{8F656DE8-12B1-4FFB-8404-16C17558E448} = {A82FA45A-B77F-48AA-8E30-C2928DCAF7EF}
{0E08B66D-9320-47D8-980C-68753A0C0574} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
{13568DA1-586D-4AD0-8834-8DBADD95207C} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
{8CF8A3F9-253A-40FD-BBA8-9E4FCA74BFBC} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
{73D40942-1B6E-4BCF-9F4F-332DEAC48A67} = {50D64CB2-C9C2-4786-A350-DA4239162FBA}
{1A0113BC-1F80-4213-B85D-DC97B85A2BA9} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
{A2902925-92FC-47D3-A040-CD06FCFC34CF} = {81BE6CDF-434E-42AB-9CB1-B5E7A26DC317}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace PostalRegistry.Api.Import
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.AggregateSource;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy.PostInfo;
using FluentValidation;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using UpdatePostalNames;

public sealed partial class PostalInformationController
{
[HttpPost("{postcode}/update-names")]
public async Task<IActionResult> UpdatePostalNames(
[FromRoute(Name = "postcode")]string? postalCode,
[FromBody] UpdatePostalNamesRequest request,
[FromServices] IValidator<UpdatePostalNamesRequest> validator,
[FromServices] IIdempotentCommandHandler idempotentCommandHandler,
CancellationToken cancellationToken = default)
{
request.PostalCode = postalCode;
await validator.ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

try
{
var command = new PostalInformation.Commands.UpdatePostalNames(
new PostalCode(postalCode!)
, request.PostalNamesToAdd.Select(MapPostalName)
, request.PostalNamesToRemove.Select(MapPostalName)
, CreateProvenance(request.Reason ?? string.Empty));

await idempotentCommandHandler.Dispatch(
command.CreateCommandId(),
command,
new Dictionary<string, object>(),
cancellationToken);

return Ok();
}
catch (AggregateNotFoundException)
{
throw new ApiException("Onbestaande postcode", StatusCodes.Status404NotFound);
}
}

private static PostalName MapPostalName(Postnaam postnaam)
{
switch (postnaam.GeografischeNaam.Taal)
{
case Taal.NL:
return new PostalName(postnaam.GeografischeNaam.Spelling, Language.Dutch);
case Taal.FR:
return new PostalName(postnaam.GeografischeNaam.Spelling, Language.French);
case Taal.DE:
return new PostalName(postnaam.GeografischeNaam.Spelling, Language.German);
case Taal.EN:
return new PostalName(postnaam.GeografischeNaam.Spelling, Language.English);
default:
throw new ArgumentOutOfRangeException(nameof(postnaam.GeografischeNaam.Taal), postnaam.GeografischeNaam.Taal, null);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace PostalRegistry.Api.Import.UpdatePostalNames
{
using System.Collections.Generic;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy.PostInfo;

public sealed class UpdatePostalNamesRequest
{
public string? PostalCode { get; set; }

public List<Postnaam> PostalNamesToAdd { get; set; } = new List<Postnaam>();
public List<Postnaam> PostalNamesToRemove { get; set; } = new List<Postnaam>();

public string? Reason { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace PostalRegistry.Api.Import.UpdatePostalNames
{
using System.Linq;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy.PostInfo;
using FluentValidation;

public sealed class UpdatePostalNamesRequestValidator : AbstractValidator<UpdatePostalNamesRequest>
{
public UpdatePostalNamesRequestValidator()
{
RuleFor(request => request.PostalCode)
.NotEmpty();

RuleFor(request => request.PostalNamesToAdd.Concat(request.PostalNamesToRemove))
.NotEmpty()
.OverridePropertyName(nameof(UpdatePostalNamesRequest.PostalNamesToAdd));

RuleFor(request => request.PostalNamesToAdd)
.Must(x =>
{
return x.Select(y => (y.GeografischeNaam.Spelling.ToLower(), y.GeografischeNaam.Taal))
.Distinct()
.Count() == x.Count;
});

RuleForEach(x => x.PostalNamesToAdd)
.SetValidator(new PostnaamValidator());

RuleForEach(x => x.PostalNamesToRemove)
.SetValidator(new PostnaamValidator());
}
}

public sealed class PostnaamValidator : AbstractValidator<Postnaam>
{
public PostnaamValidator()
{
RuleFor(request => request.GeografischeNaam)
.NotNull();

RuleFor(request => request.GeografischeNaam.Spelling)
.NotEmpty();
}
}
}
1 change: 1 addition & 0 deletions src/PostalRegistry.Api.Import/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Be.Vlaanderen.Basisregisters.Api
Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency
Be.Vlaanderen.Basisregisters.EventHandling.Autofac
Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Autofac
Be.Vlaanderen.Basisregisters.GrAr.Legacy

AspNetCore.HealthChecks.SqlServer

Expand Down
Loading
Loading