Skip to content

Commit

Permalink
feat: add correct address removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rikdepeuter authored and ArneD committed May 29, 2024
1 parent e8f80dc commit 6c3f731
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Common/Infrastructure/FeatureToggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public class CorrectDeregulationAddressToggle : IFeatureToggle
public CorrectDeregulationAddressToggle(bool featureEnabled) => FeatureEnabled = featureEnabled;
}

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

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

public class ReaddressStreetNameAddressesToggle : IFeatureToggle
{
public bool FeatureEnabled { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
namespace Public.Api.Address.BackOffice
{
using System.Threading;
using System.Threading.Tasks;
using AddressRegistry.Api.Oslo.Address.Detail;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
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;

public partial class AddressBackOfficeController
{
public const string CorrectRemovalRoute = "adressen/{objectId}/acties/corrigeren/verwijdering";

/// <summary>
/// Corrigeer de verwijdering van een adres (v2).
/// </summary>
/// <param name="objectId">Identificator van het adres.</param>
/// <param name="actionContextAccessor"></param>
/// <param name="problemDetailsHelper"></param>
/// <param name="featureToggle"></param>
/// <param name="ifMatch">If-Match header met ETag van de laatst gekende versie van het adres (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 het adres 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.Address.Edit + 16)]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.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.")]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status401Unauthorized, typeof(UnauthorizedOAuthResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status403Forbidden, typeof(ForbiddenOAuthResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status404NotFound, typeof(AddressNotFoundResponseExamples))]
[SwaggerResponseExample(StatusCodes.Status412PreconditionFailed, typeof(PreconditionFailedResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status429TooManyRequests, typeof(TooManyRequestsResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamplesV2))]
[SwaggerOperation(Description = "Correctie van de verwijdering van een adres. Gekoppelde busnummers worden niet mee gecorrigeerd.")]
[HttpPost(CorrectRemovalRoute, Name = nameof(CorrectRemovalAddress))]
public async Task<IActionResult> CorrectRemovalAddress(
[FromRoute] int objectId,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] CorrectRemovalAddressToggle featureToggle,
[FromHeader(Name = HeaderNames.IfMatch)] string? ifMatch,
CancellationToken cancellationToken = default)
{
if (!featureToggle.FeatureEnabled)
{
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => new RestRequest(CorrectRemovalRoute, 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 @@ -36,6 +36,7 @@ public class FeatureToggleOptions
public bool CorrectRetirementAddress { get; set; }
public bool CorrectRegularizationAddress { get; set; }
public bool CorrectDeregulationAddress { get; set; }
public bool CorrectRemovalAddress { get; set; }
public bool ReaddressStreetNameAddresses { get; set; }

public bool PlanBuilding { 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 @@ -364,6 +364,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.AddSingleton(c => new CorrectRetirementAddressToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectRetirementAddress))
.AddSingleton(c => new CorrectRegularizationAddressToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectRegularizationAddress))
.AddSingleton(c => new CorrectDeregulationAddressToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectDeregulationAddress))
.AddSingleton(c => new CorrectRemovalAddressToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.CorrectRemovalAddress))
.AddSingleton(c => new ReaddressStreetNameAddressesToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.ReaddressStreetNameAddresses))

.AddSingleton(c => new PlanBuildingToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.PlanBuilding))
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 @@ -441,6 +441,7 @@
"CorrectRetirementAddress": false,
"CorrectRegularizationAddress": false,
"CorrectDeregulationAddress": false,
"CorrectRemovalAddress": false,
"ReaddressStreetNameAddresses": false,

"PlanBuilding": false,
Expand Down

0 comments on commit 6c3f731

Please sign in to comment.