Skip to content

Commit

Permalink
feat: move building unit
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Apr 12, 2024
1 parent 6f10ff6 commit fc416d9
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 6 deletions.
6 changes: 3 additions & 3 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ nuget Be.Vlaanderen.Basisregisters.PostalRegistry.Api.Oslo 5.0.0 c
nuget Be.Vlaanderen.Basisregisters.StreetNameRegistry.Api.Legacy 4.0.7 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.StreetNameRegistry.Api.Oslo 4.0.7 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.StreetNameRegistry.Api.BackOffice.Abstractions 4.0.7 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Legacy 4.1.10 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Oslo 4.1.10 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.BackOffice.Abstractions 4.1.10 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Legacy 4.2.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Oslo 4.2.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.BackOffice.Abstractions 4.2.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Legacy 4.0.8 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Oslo 4.0.8 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.BackOffice.Abstractions 4.0.8 copy_content_to_output_dir: always
Expand Down
6 changes: 3 additions & 3 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ NUGET
Microsoft.Data.SqlClient (>= 5.2)
System.Collections.Immutable (>= 8.0)
Be.Vlaanderen.Basisregisters.Build.Pipeline (7.2.5)
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.BackOffice.Abstractions (4.1.10) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.BackOffice.Abstractions (4.2) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.Api (>= 23.1)
MediatR.Contracts (>= 2.0.1)
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Legacy (4.1.10) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Oslo (4.1.10) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Legacy (4.2) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Oslo (4.2) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.CommandHandling (9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency (9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (9.0.1)
Expand Down
7 changes: 7 additions & 0 deletions src/Common/Infrastructure/FeatureToggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ public class CorrectFunctionBuildingUnitToggle : IFeatureToggle
public CorrectFunctionBuildingUnitToggle(bool featureEnabled) => FeatureEnabled = featureEnabled;
}

public class MoveBuildingUnitToggle : IFeatureToggle
{
public bool FeatureEnabled { get; }

public MoveBuildingUnitToggle(bool featureEnabled) => FeatureEnabled = featureEnabled;
}

public class AttachAddressParcelToggle : IFeatureToggle
{
public bool FeatureEnabled { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace Public.Api.BuildingUnit.BackOffice
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using BuildingRegistry.Api.BackOffice.Abstractions.BuildingUnit.Requests;
using BuildingRegistry.Api.Oslo.BuildingUnit.Detail;
using Common.Infrastructure;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Infrastructure.Swagger;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using RestSharp;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.Filters;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
using ValidationProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails;

public partial class BuildingUnitBackOfficeController
{
public const string MoveBuildingUnitRoute = "gebouweenheden/{objectId}/acties/verplaatsen";

/// <summary>
/// Verplaats de gebouweenheid naar het doelgebouw (v2).
/// </summary>
/// <param name="objectId">Identificator van de gebouweenheid.</param>
/// <param name="moveBuildingUnitRequest"></param>
/// <param name="actionContextAccessor"></param>
/// <param name="problemDetailsHelper"></param>
/// <param name="moveBuildingUnitToggle"></param>
/// <param name="ifMatch">If-Match header met ETag van de laatst gekende versie van de gebouweenheid (optioneel).</param>
/// <param name="cancellationToken"></param>
/// <response code="202">Als het ticket succesvol is aangemaakt.</response>
/// <response code="400">Als uw verzoek foutieve data bevat.</response>
/// <response code="401">Als u niet geauthenticeerd bent om deze actie uit te voeren.</response>
/// <response code="403">Als u niet beschikt over de correcte rechten om deze actie uit te voeren.</response>
/// <response code="404">Als de gebouweenheid niet gevonden kan worden.</response>
/// <response code="406">Als het gevraagde formaat niet beschikbaar is.</response>
/// <response code="412">Als de If-Match header niet overeenkomt met de laatste ETag.</response>
/// <response code="429">Als het aantal requests per seconde de limiet overschreven heeft.</response>
/// <response code="500">Als er een interne fout is opgetreden.</response>
/// <returns></returns>
[ApiOrder(ApiOrder.BuildingUnit.Edit + 20)]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[SwaggerResponseHeader(StatusCodes.Status202Accepted, "location", "string", "De URL van het aangemaakte ticket.")]
[SwaggerResponseHeader(StatusCodes.Status202Accepted, "x-correlation-id", "string", "Correlatie identificator van de response.")]
[SwaggerRequestExample(typeof(MoveBuildingUnitRequest), typeof(MoveBuildingUnitRequestExamples))]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status401Unauthorized, typeof(UnauthorizedOAuthResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status403Forbidden, typeof(ForbiddenOAuthResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status404NotFound, typeof(BuildingUnitNotFoundResponseExamples))]
[SwaggerResponseExample(StatusCodes.Status412PreconditionFailed, typeof(PreconditionFailedResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status429TooManyRequests, typeof(TooManyRequestsResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamplesV2))]
[SwaggerOperation(Description = "Verplaats de gebouweenheid naar het doelgebouw.")]
[HttpPost(MoveBuildingUnitRoute, Name = nameof(MoveBuildingUnit))]
public async Task<IActionResult> MoveBuildingUnit(
[FromRoute] int objectId,
[FromBody] MoveBuildingUnitRequest moveBuildingUnitRequest,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] MoveBuildingUnitToggle moveBuildingUnitToggle,
[FromHeader(Name = HeaderNames.IfMatch)] string? ifMatch,
CancellationToken cancellationToken = default)
{
if (!moveBuildingUnitToggle.FeatureEnabled)
{
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() =>
CreateBackendRequestWithJsonBody(MoveBuildingUnitRoute, moveBuildingUnitRequest, Method.Post)
.AddParameter("objectId", objectId, ParameterType.UrlSegment)
.AddHeaderIfMatch(ifMatch)
.AddHeaderAuthorization(actionContextAccessor);

var value = await GetFromBackendWithBadRequestAsync(
contentFormat.ContentType,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class FeatureToggleOptions
public bool CorrectFunctionBuildingUnit { get; set; }
public bool CorrectBuildingUnitPosition { get; set; }
public bool RemoveBuildingUnit { get; set; }
public bool MoveBuildingUnit { get; set; }

public bool AttachAddressParcel { get; set; }
public bool DetachAddressParcel { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Public.Api/Infrastructure/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.AddSingleton(c => new CorrectFunctionBuildingUnitToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectFunctionBuildingUnit))
.AddSingleton(c => new CorrectBuildingUnitPositionToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectBuildingUnitPosition))
.AddSingleton(c => new RemoveBuildingUnitToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.RemoveBuildingUnit))
.AddSingleton(c => new MoveBuildingUnitToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.MoveBuildingUnit))

.AddSingleton(c => new AttachAddressParcelToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.AttachAddressParcel))
.AddSingleton(c => new DetachAddressParcelToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.DetachAddressParcel))
Expand Down
1 change: 1 addition & 0 deletions src/Public.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@
"CorrectBuildingUnitRetirement": false,
"CorrectBuildingUnitRegularization": false,
"CorrectBuildingUnitDeregulation": false,
"MoveBuildingUnit": false,

"AttachAddressParcel": false,
"DetachAddressParcel": false,
Expand Down

0 comments on commit fc416d9

Please sign in to comment.