-
Notifications
You must be signed in to change notification settings - Fork 10
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
20 changed files
with
555 additions
and
45 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
7 changes: 7 additions & 0 deletions
7
...ngRegistry.Api.BackOffice.Abstractions/Building/Requests/CreateBuildingSnapshotRequest.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,7 @@ | ||
namespace BuildingRegistry.Api.BackOffice.Abstractions.Building.Requests | ||
{ | ||
public sealed class CreateBuildingSnapshotRequest | ||
{ | ||
public int PersistentLocalId { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...stry.Api.BackOffice.Abstractions/Building/SqsRequests/CreateBuildingSnapshotSqsRequest.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 BuildingRegistry.Api.BackOffice.Abstractions.Building.SqsRequests | ||
{ | ||
using Be.Vlaanderen.Basisregisters.Sqs.Requests; | ||
using Requests; | ||
|
||
public sealed class CreateBuildingSnapshotSqsRequest : SqsRequest | ||
{ | ||
public CreateBuildingSnapshotRequest Request { get; set; } | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...y.Api.BackOffice.Handlers.Lambda/Handlers/Building/CreateBuildingSnapshotLambdaHandler.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,56 @@ | ||
namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Handlers.Building | ||
{ | ||
using Abstractions; | ||
using Abstractions.Validation; | ||
using Be.Vlaanderen.Basisregisters.AggregateSource; | ||
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Infrastructure; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Responses; | ||
using BuildingRegistry.Building; | ||
using BuildingRegistry.Building.Exceptions; | ||
using Microsoft.Extensions.Configuration; | ||
using Requests.Building; | ||
using TicketingService.Abstractions; | ||
|
||
public sealed class CreateBuildingSnapshotLambdaHandler : BuildingLambdaHandler<CreateBuildingSnapshotLambdaRequest> | ||
{ | ||
public CreateBuildingSnapshotLambdaHandler( | ||
IConfiguration configuration, | ||
ICustomRetryPolicy retryPolicy, | ||
ITicketing ticketing, | ||
IIdempotentCommandHandler idempotentCommandHandler, | ||
IBuildings buildings) | ||
: base( | ||
configuration, | ||
retryPolicy, | ||
ticketing, | ||
idempotentCommandHandler, | ||
buildings) | ||
{ } | ||
|
||
protected override async Task<object> InnerHandle(CreateBuildingSnapshotLambdaRequest 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, CreateBuildingSnapshotLambdaRequest 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
38 changes: 38 additions & 0 deletions
38
...y.Api.BackOffice.Handlers.Lambda/Requests/Building/CreateBuildingSnapshotLambdaRequest.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,38 @@ | ||
namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Requests.Building | ||
{ | ||
using Abstractions.Building.Requests; | ||
using Abstractions.Building.SqsRequests; | ||
using BuildingRegistry.Building; | ||
using BuildingRegistry.Building.Commands; | ||
using IHasBuildingPersistentLocalId = Abstractions.IHasBuildingPersistentLocalId; | ||
|
||
public sealed record CreateBuildingSnapshotLambdaRequest : BuildingLambdaRequest, IHasBuildingPersistentLocalId | ||
{ | ||
public CreateBuildingSnapshotRequest Request { get; } | ||
public int BuildingPersistentLocalId => Request.PersistentLocalId; | ||
|
||
public CreateBuildingSnapshotLambdaRequest( | ||
string messageGroupId, | ||
CreateBuildingSnapshotSqsRequest 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 BuildingPersistentLocalId(BuildingPersistentLocalId), | ||
Provenance); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/BuildingRegistry.Api.BackOffice/Building/BuildingController-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,61 @@ | ||
namespace BuildingRegistry.Api.BackOffice.Building | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Abstractions.Building.Requests; | ||
using Abstractions.Building.Validators; | ||
using Abstractions.Building.SqsRequests; | ||
using Abstractions.Validation; | ||
using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; | ||
using Be.Vlaanderen.Basisregisters.Api.ETag; | ||
using Be.Vlaanderen.Basisregisters.Api.Exceptions; | ||
using Be.Vlaanderen.Basisregisters.GrAr.Provenance; | ||
using BuildingRegistry.Building; | ||
using Infrastructure; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Filters; | ||
|
||
public partial class BuildingController | ||
{ | ||
/// <summary> | ||
/// Snapshot voor het gebouw aanvragen. | ||
/// </summary> | ||
/// <param name="buildingExistsValidator"></param> | ||
/// <param name="request"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <response code="202">Als de snapshot voor het gebouw aangevraagd is.</response> | ||
/// <returns></returns> | ||
[HttpPost("{persistentLocalId}/acties/snapshot")] | ||
[ProducesResponseType(StatusCodes.Status202Accepted)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] | ||
[SwaggerResponseHeader(StatusCodes.Status202Accepted, "location", "string", "De url van het gebouw.")] | ||
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamples))] | ||
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamples))] | ||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.GeschetstGebouw.InterneBijwerker)] | ||
public async Task<IActionResult> CreateSnapshot( | ||
[FromServices] BuildingExistsValidator buildingExistsValidator, | ||
[FromRoute] CreateBuildingSnapshotRequest request, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
if (!await buildingExistsValidator.Exists(new BuildingPersistentLocalId(request.PersistentLocalId), | ||
cancellationToken)) | ||
{ | ||
throw new ApiException(ValidationErrors.Common.BuildingNotFound.Message, StatusCodes.Status404NotFound); | ||
} | ||
|
||
var result = await Mediator.Send( | ||
new CreateBuildingSnapshotSqsRequest | ||
{ | ||
Request = request, | ||
Metadata = GetMetadata(), | ||
ProvenanceData = new ProvenanceData(CreateProvenance(Modification.Unknown)), | ||
}, cancellationToken); | ||
|
||
return Accepted(result); | ||
} | ||
} | ||
} |
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
src/BuildingRegistry.Api.BackOffice/Handlers/Building/CreateBuildingSnapshotSqsHandler.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,35 @@ | ||
namespace BuildingRegistry.Api.BackOffice.Handlers.Building | ||
{ | ||
using System.Collections.Generic; | ||
using Abstractions.Building.SqsRequests; | ||
using AllStream; | ||
using Be.Vlaanderen.Basisregisters.Sqs; | ||
using Be.Vlaanderen.Basisregisters.Sqs.Handlers; | ||
using TicketingService.Abstractions; | ||
|
||
public sealed class CreateBuildingSnapshotSqsHandler : SqsHandler<CreateBuildingSnapshotSqsRequest> | ||
{ | ||
public const string Action = "CreateBuildingSnapshot"; | ||
|
||
public CreateBuildingSnapshotSqsHandler( | ||
ISqsQueue sqsQueue, | ||
ITicketing ticketing, | ||
ITicketingUrl ticketingUrl) : base(sqsQueue, ticketing, ticketingUrl) | ||
{ } | ||
|
||
protected override string? WithAggregateId(CreateBuildingSnapshotSqsRequest request) | ||
{ | ||
return request.Request.PersistentLocalId.ToString(); | ||
} | ||
|
||
protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, CreateBuildingSnapshotSqsRequest sqsRequest) | ||
{ | ||
return new Dictionary<string, string> | ||
{ | ||
{ RegistryKey, nameof(BuildingRegistry) }, | ||
{ 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.