-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
782 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/PostalRegistry.Api.Import/PostalInformationController-RelinkMunicipality.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace PostalRegistry.Api.Import | ||
{ | ||
using System.Collections.Generic; | ||
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 FluentValidation; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using PostalInformation.Commands; | ||
using Relink; | ||
|
||
public sealed partial class PostalInformationController | ||
{ | ||
[HttpPost("{postcode}/relink-municipality")] | ||
public async Task<IActionResult> RelinkMunicipality( | ||
[FromRoute(Name = "postcode")]string? postalCode, | ||
[FromBody] RelinkMunicipalityRequest request, | ||
[FromServices] IValidator<RelinkMunicipalityRequest> validator, | ||
[FromServices] IIdempotentCommandHandler idempotentCommandHandler, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
request.PostalCode = postalCode; | ||
await validator.ValidateAndThrowAsync(request, cancellationToken: cancellationToken); | ||
|
||
try | ||
{ | ||
var command = new RelinkMunicipality( | ||
new PostalCode(postalCode!) | ||
, new NisCode(request.NewNisCode!) | ||
, 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); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/PostalRegistry.Api.Import/PostalInformationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace PostalRegistry.Api.Import | ||
{ | ||
using Asp.Versioning; | ||
using Be.Vlaanderen.Basisregisters.Api; | ||
using Be.Vlaanderen.Basisregisters.GrAr.Provenance; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NodaTime; | ||
|
||
[ApiVersion("1.0")] | ||
[AdvertiseApiVersions("1.0")] | ||
[ApiRoute("import")] | ||
[ApiExplorerSettings(GroupName = "Import")] | ||
public sealed partial class PostalInformationController : ApiController | ||
{ | ||
private Provenance CreateProvenance(string reason, Modification modification = Modification.Update) | ||
{ | ||
return new Provenance( | ||
SystemClock.Instance.GetCurrentInstant(), | ||
Application.PostalRegistry, | ||
new Reason(reason), | ||
new Operator("OVO002949"), | ||
modification, | ||
Organisation.DigitaalVlaanderen); | ||
} | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
src/PostalRegistry.Api.Import/PostalRegistry.Api.Import.csproj.DotSettings
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
src/PostalRegistry.Api.Import/Relink/RelinkMunicipalityRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PostalRegistry.Api.Import.Relink | ||
{ | ||
public sealed class RelinkMunicipalityRequest | ||
{ | ||
public string? PostalCode { get; set; } | ||
public string? NewNisCode { get; set; } | ||
|
||
public string? Reason { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/PostalRegistry.Api.Import/Relink/RelinkMunicipalityRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace PostalRegistry.Api.Import.Relink | ||
{ | ||
using FluentValidation; | ||
|
||
public sealed class RelinkMunicipalityRequestValidator : AbstractValidator<RelinkMunicipalityRequest> | ||
{ | ||
public RelinkMunicipalityRequestValidator() | ||
{ | ||
RuleFor(request => request.PostalCode) | ||
.NotEmpty(); | ||
|
||
RuleFor(request => request.NewNisCode) | ||
.NotEmpty() | ||
.Length(5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/PostalRegistry/PostalInformation/Commands/RelinkMunicipality.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace PostalRegistry.PostalInformation.Commands | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Be.Vlaanderen.Basisregisters.Generators.Guid; | ||
using Be.Vlaanderen.Basisregisters.GrAr.Provenance; | ||
using Be.Vlaanderen.Basisregisters.Utilities; | ||
|
||
public sealed class RelinkMunicipality : IHasCommandProvenance | ||
{ | ||
private static readonly Guid Namespace = new Guid("461f480c-75d9-4637-b98e-5fd66682d338"); | ||
|
||
public PostalCode PostalCode { get; } | ||
public NisCode NewNisCode { get; } | ||
public Provenance Provenance { get; } | ||
|
||
public RelinkMunicipality(PostalCode postalCode, NisCode newNisCode, Provenance provenance) | ||
{ | ||
PostalCode = postalCode; | ||
NewNisCode = newNisCode; | ||
Provenance = provenance; | ||
} | ||
|
||
public Guid CreateCommandId() | ||
=> Deterministic.Create(Namespace, $"RelinkMunicipality-{ToString()}"); | ||
|
||
public override string? ToString() | ||
=> ToStringBuilder.ToString(IdentityFields()); | ||
|
||
private IEnumerable<object> IdentityFields() | ||
{ | ||
yield return PostalCode; | ||
yield return NewNisCode; | ||
|
||
foreach (var field in Provenance.GetIdentityFields()) | ||
{ | ||
yield return field; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.