-
Notifications
You must be signed in to change notification settings - Fork 9
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
25 changed files
with
688 additions
and
94 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
16 changes: 16 additions & 0 deletions
16
src/AddressRegistry.Api.BackOffice.Abstractions/Requests/CreateStreetNameSnapshotRequest.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,16 @@ | ||
namespace AddressRegistry.Api.BackOffice.Abstractions.Requests | ||
{ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
|
||
[DataContract(Name = "SnapshotStraatnaam", Namespace = "")] | ||
public sealed class CreateStreetNameSnapshotRequest | ||
{ | ||
/// <summary> | ||
/// De unieke en persistente identificator van de straatnaam. | ||
/// </summary> | ||
[DataMember(Name = "StreetNamePersistentLocalId", Order = 0)] | ||
[JsonProperty(Required = Required.Always)] | ||
public int StreetNamePersistentLocalId { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...essRegistry.Api.BackOffice.Abstractions/SqsRequests/CreateStreetNameSnapshotSqsRequest.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 AddressRegistry.Api.BackOffice.Abstractions.SqsRequests | ||
{ | ||
using Be.Vlaanderen.Basisregisters.Sqs.Requests; | ||
using Requests; | ||
|
||
public sealed class CreateStreetNameSnapshotSqsRequest : SqsRequest | ||
{ | ||
public CreateStreetNameSnapshotRequest Request { get; init; } | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...Registry.Api.BackOffice.Handlers.Lambda/Handlers/CreateStreetNameSnapshotLambdaHandler.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,52 @@ | ||
namespace AddressRegistry.Api.BackOffice.Handlers.Lambda.Handlers | ||
{ | ||
using Be.Vlaanderen.Basisregisters.AggregateSource; | ||
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Infrastructure; | ||
using Microsoft.Extensions.Configuration; | ||
using Requests; | ||
using StreetName; | ||
using TicketingService.Abstractions; | ||
|
||
public sealed class CreateStreetNameSnapshotLambdaHandler : SqsLambdaHandler<CreateStreetNameSnapshotLambdaRequest> | ||
{ | ||
public CreateStreetNameSnapshotLambdaHandler( | ||
IConfiguration configuration, | ||
ICustomRetryPolicy retryPolicy, | ||
ITicketing ticketing, | ||
IStreetNames streetNames, | ||
IIdempotentCommandHandler idempotentCommandHandler) | ||
: base( | ||
configuration, | ||
retryPolicy, | ||
streetNames, | ||
ticketing, | ||
idempotentCommandHandler) | ||
{ } | ||
|
||
protected override async Task<object> InnerHandle(CreateStreetNameSnapshotLambdaRequest request, CancellationToken cancellationToken) | ||
{ | ||
var cmd = request.ToCommand(); | ||
|
||
try | ||
{ | ||
await IdempotentCommandHandler.Dispatch( | ||
cmd.CreateCommandId(), | ||
cmd, | ||
request.Metadata!, | ||
cancellationToken); | ||
} | ||
catch (IdempotencyException) | ||
{ | ||
// Idempotent: Do Nothing return last etag | ||
} | ||
|
||
return "snapshot created"; | ||
} | ||
|
||
protected override TicketError? InnerMapDomainException(DomainException exception, CreateStreetNameSnapshotLambdaRequest request) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...Registry.Api.BackOffice.Handlers.Lambda/Requests/CreateStreetNameSnapshotLambdaRequest.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,39 @@ | ||
namespace AddressRegistry.Api.BackOffice.Handlers.Lambda.Requests | ||
{ | ||
using Abstractions.Requests; | ||
using Abstractions.SqsRequests; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Requests; | ||
using StreetName; | ||
using StreetName.Commands; | ||
|
||
public sealed record CreateStreetNameSnapshotLambdaRequest : | ||
SqsLambdaRequest, | ||
IHasBackOfficeRequest<CreateStreetNameSnapshotRequest> | ||
{ | ||
public CreateStreetNameSnapshotRequest Request { get; init; } | ||
|
||
public CreateStreetNameSnapshotLambdaRequest( | ||
string messageGroupId, | ||
CreateStreetNameSnapshotSqsRequest sqsRequest) | ||
: base( | ||
messageGroupId, | ||
sqsRequest.TicketId, | ||
null, | ||
sqsRequest.ProvenanceData.ToProvenance(), | ||
sqsRequest.Metadata) | ||
{ | ||
Request = sqsRequest.Request; | ||
} | ||
|
||
/// <summary> | ||
/// Map to CreateSnapshot command. | ||
/// </summary> | ||
/// <returns>CreateSnapshot</returns> | ||
public CreateSnapshot ToCommand() | ||
{ | ||
return new CreateSnapshot( | ||
new StreetNamePersistentLocalId(Request.StreetNamePersistentLocalId), | ||
Provenance); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/AddressRegistry.Api.BackOffice/AddressController-CreateSnapshot.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,58 @@ | ||
namespace AddressRegistry.Api.BackOffice | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Abstractions.Requests; | ||
using Abstractions.SqsRequests; | ||
using Abstractions.Validation; | ||
using Be.Vlaanderen.Basisregisters.Api.Exceptions; | ||
using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; | ||
using Be.Vlaanderen.Basisregisters.GrAr.Provenance; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Exceptions; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Filters; | ||
|
||
public partial class AddressController | ||
{ | ||
/// <summary> | ||
/// Snapshot voor de straatnaam aanvragen. | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <response code="202">Als de snapshot voor de straatnaam aangevraagd is.</response> | ||
/// <returns></returns> | ||
[HttpPost("acties/snapshot")] | ||
[ProducesResponseType(StatusCodes.Status202Accepted)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status412PreconditionFailed)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] | ||
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamples))] | ||
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamples))] | ||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.Adres.InterneBijwerker)] | ||
public async Task<IActionResult> CreateSnapshot( | ||
[FromBody] CreateStreetNameSnapshotRequest request, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var sqsRequest = new CreateStreetNameSnapshotSqsRequest | ||
{ | ||
Request = request, | ||
Metadata = GetMetadata(), | ||
ProvenanceData = new ProvenanceData(CreateProvenance(Modification.Unknown)), | ||
}; | ||
|
||
var sqsResult = await _mediator.Send(sqsRequest, cancellationToken); | ||
|
||
return Accepted(sqsResult); | ||
} | ||
catch (AggregateIdIsNotFoundException) | ||
{ | ||
throw new ApiException(ValidationErrors.Common.AddressNotFound.Message, StatusCodes.Status404NotFound); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/AddressRegistry.Api.BackOffice/Handlers/CreateStreetNameSnapshotSqsHandler.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,45 @@ | ||
namespace AddressRegistry.Api.BackOffice.Handlers | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Abstractions; | ||
using Abstractions.SqsRequests; | ||
using Be.Vlaanderen.Basisregisters.Sqs; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Handlers; | ||
using TicketingService.Abstractions; | ||
|
||
public sealed class CreateStreetNameSnapshotSqsHandler : SqsHandler<CreateStreetNameSnapshotSqsRequest> | ||
{ | ||
public const string Action = "CreateStreetNameSnapshot"; | ||
|
||
private readonly BackOfficeContext _backOfficeContext; | ||
|
||
public CreateStreetNameSnapshotSqsHandler( | ||
ISqsQueue sqsQueue, | ||
ITicketing ticketing, | ||
ITicketingUrl ticketingUrl, | ||
BackOfficeContext backOfficeContext) | ||
: base(sqsQueue, ticketing, ticketingUrl) | ||
{ | ||
_backOfficeContext = backOfficeContext; | ||
} | ||
|
||
protected override string? WithAggregateId(CreateStreetNameSnapshotSqsRequest request) | ||
{ | ||
return _backOfficeContext | ||
.AddressPersistentIdStreetNamePersistentIds | ||
.SingleOrDefault(x => x.StreetNamePersistentLocalId == request.Request.StreetNamePersistentLocalId) | ||
?.StreetNamePersistentLocalId.ToString(); | ||
} | ||
|
||
protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, CreateStreetNameSnapshotSqsRequest sqsRequest) | ||
{ | ||
return new Dictionary<string, string> | ||
{ | ||
{ RegistryKey, nameof(AddressRegistry) }, | ||
{ ActionKey, Action }, | ||
{ AggregateIdKey, aggregateId } | ||
}; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.