Skip to content

Commit

Permalink
feat: add address search
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Sep 2, 2024
1 parent 35ff8c7 commit f8f5326
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 20 deletions.
14 changes: 7 additions & 7 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ nuget Be.Vlaanderen.Basisregisters.StreetNameRegistry.Api.Oslo 4.5.1 c
nuget Be.Vlaanderen.Basisregisters.StreetNameRegistry.Api.BackOffice.Abstractions 4.5.1 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.Oslo 4.10.1 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.BuildingRegistry.Api.BackOffice.Abstractions 4.10.1 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Oslo 4.7.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.BackOffice.Abstractions 4.7.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Oslo 4.17.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.AddressRegistry.Api.BackOffice.Abstractions 4.17.0 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.ParcelRegistry.Api.Oslo 5.5.3 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.ParcelRegistry.Api.BackOffice.Abstractions 5.5.3 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice 4.3.0 copy_content_to_output_dir: always
Expand All @@ -40,11 +40,11 @@ nuget Be.Vlaanderen.Basisregisters.AggregateSource.ExplicitRouting 9.0.1
nuget Be.Vlaanderen.Basisregisters.Auth.AcmIdm 2.0.0
nuget Be.Vlaanderen.Basisregisters.Api 23.1.0

nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.7.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.7.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.7.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.7.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.7.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.14.1

nuget Be.Vlaanderen.Basisregisters.EventHandling 5.0.0
nuget Be.Vlaanderen.Basisregisters.ProblemDetails 9.0.0
Expand Down
20 changes: 10 additions & 10 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ NUGET
System.Security.Cryptography.ProtectedData (>= 4.7)
System.Text.Json (>= 4.7.2)
System.Threading.Tasks.Extensions (>= 4.5.4)
Be.Vlaanderen.Basisregisters.AddressRegistry.Api.BackOffice.Abstractions (4.7) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.AddressRegistry.Api.BackOffice.Abstractions (4.17) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.Api (>= 23.1)
MediatR.Contracts (>= 2.0.1)
Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Oslo (4.7) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.GrAr.Legacy (>= 21.5)
Be.Vlaanderen.Basisregisters.AddressRegistry.Api.Oslo (4.17) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.GrAr.Legacy (>= 21.14.1)
MediatR.Contracts (>= 2.0.1)
Be.Vlaanderen.Basisregisters.AggregateSource (9.0.1)
Be.Vlaanderen.Basisregisters.Utilities.HashCodeCalculator (>= 4.0)
Expand Down Expand Up @@ -210,14 +210,14 @@ NUGET
Autofac.Extensions.DependencyInjection (>= 9.0)
Be.Vlaanderen.Basisregisters.EventHandling (5.0)
Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
NetTopologySuite (>= 2.5)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.14.1)
NetTopologySuite (>= 2.5)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.14.1)
Autofac (>= 8.0)
Be.Vlaanderen.Basisregisters.AggregateSource.SqlStreamStore (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Expand All @@ -232,14 +232,14 @@ NUGET
Serilog (>= 3.1.1)
Serilog.Extensions.Logging (>= 8.0)
System.Threading.Tasks.Dataflow (>= 8.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.14.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.14.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.7)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions (2.1) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.Api (>= 23.1)
Expand Down
3 changes: 2 additions & 1 deletion src/Common/Infrastructure/EndpointType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum EndpointType
Legacy,
Sync,
BackOffice,
Oslo
Oslo,
Json
}
}
7 changes: 7 additions & 0 deletions src/Common/Infrastructure/FeatureToggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ public class CorrectRemovalAddressToggle : IFeatureToggle
public CorrectRemovalAddressToggle(bool featureEnabled) => FeatureEnabled = featureEnabled;
}

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

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

public class ReaddressStreetNameAddressesToggle : IFeatureToggle
{
public bool FeatureEnabled { get; }
Expand Down
3 changes: 3 additions & 0 deletions src/Public.Api/Address/Oslo/AddressController-AddressMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Public.Api.Address.Oslo
using AddressRegistry.Api.Oslo.AddressMatch.Responses;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Common.Infrastructure;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Infrastructure.Swagger;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -39,6 +41,7 @@ public partial class AddressOsloController
/// <response code="500">Als er een interne fout is opgetreden.</response>
[HttpGet("adresmatch", Name = nameof(AddressMatchV2))]
[ApiOrder(ApiOrder.Address.V2 + 4)]
[ApiProduces(EndpointType.Oslo)]
[ProducesResponseType(typeof(AddressMatchOsloCollection), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
Expand Down
2 changes: 2 additions & 0 deletions src/Public.Api/Address/Oslo/AddressController-Count.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Public.Api.Address.Oslo
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Common.Infrastructure;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Infrastructure.Swagger;
using Marvin.Cache.Headers;
Expand Down Expand Up @@ -38,6 +39,7 @@ public partial class AddressOsloController
/// <response code="500">Als er een interne fout is opgetreden.</response>
[HttpGet("adressen/totaal-aantal", Name = nameof(CountAddressesV2))]
[ApiOrder(ApiOrder.Address.V2 + 3)]
[ApiProduces(EndpointType.Oslo)]
[ApiExplorerSettings(IgnoreApi = true)]
[ProducesResponseType(typeof(TotaalAantalResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails), StatusCodes.Status400BadRequest)]
Expand Down
2 changes: 2 additions & 0 deletions src/Public.Api/Address/Oslo/AddressController-Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Public.Api.Address.Oslo
using Be.Vlaanderen.Basisregisters.Api.ETag;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Infrastructure.Swagger;
using Marvin.Cache.Headers;
Expand Down Expand Up @@ -36,6 +37,7 @@ public partial class AddressOsloController
/// <response code="500">Als er een interne fout is opgetreden.</response>
[HttpGet("adressen/{objectId}", Name = nameof(GetAddressV2))]
[ApiOrder(ApiOrder.Address.V2 + 1)]
[ApiProduces(EndpointType.Oslo)]
[ProducesResponseType(typeof(AddressDetailOsloResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status304NotModified)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails), StatusCodes.Status400BadRequest)]
Expand Down
2 changes: 2 additions & 0 deletions src/Public.Api/Address/Oslo/AddressController-List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Public.Api.Address.Oslo
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Common.Infrastructure;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Infrastructure.Configuration;
using Infrastructure.Swagger;
Expand Down Expand Up @@ -51,6 +52,7 @@ public partial class AddressOsloController
/// <response code="500">Als er een interne fout is opgetreden.</response>
[HttpGet("adressen", Name = nameof(ListAddressesV2))]
[ApiOrder(ApiOrder.Address.V2 + 2)]
[ApiProduces(EndpointType.Oslo)]
[ProducesResponseType(typeof(AddressListOsloResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
Expand Down
106 changes: 106 additions & 0 deletions src/Public.Api/Address/Oslo/AddressController-Search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Public.Api.Address.Oslo
{
using System.Threading;
using System.Threading.Tasks;
using AddressRegistry.Api.Oslo.Address.Search;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Infrastructure.Configuration;
using Infrastructure.Swagger;
using Marvin.Cache.Headers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Options;
using RestSharp;
using Swashbuckle.AspNetCore.Filters;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;

public partial class AddressOsloController
{
private const int MaxSearchLimit = 50;
private const int DefaultSearchLimit = 10;

/// <summary>
/// Zoeken naar adressen of straatnamen via een query.
/// </summary>
/// <param name="query">De zoek query.</param>
/// <param name="municipalityOrPostalName">Limiteer de zoek query in een te zoeken gemeente- of postnaam (optioneel).</param>
/// <param name="limit">Aantal instanties dat teruggegeven wordt. Maximaal kunnen er 50 worden teruggegeven. Wanneer limit niet wordt meegegeven dan default 10 instanties (optioneel).</param>
/// <param name="searchAddressesToggle"></param>
/// <param name="actionContextAccessor"></param>
/// <param name="responseOptions"></param>
/// <param name="cancellationToken"></param>
/// <response code="200">Als de opvraging van de zoekopdracht gelukt is.</response>
/// <response code="400">Als uw verzoek foutieve data bevat.</response>
/// <response code="403">Als u niet beschikt over de correcte rechten om deze actie uit te voeren.</response>
/// <response code="406">Als het gevraagde formaat niet beschikbaar is.</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>
[HttpGet("adressen/zoeken", Name = nameof(SearchAddresses))]
[ApiOrder(ApiOrder.Address.V2 + 5)]
[ApiProduces(EndpointType.Json)]
[ProducesResponseType(typeof(AddressSearchResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[SwaggerResponseHeader(StatusCodes.Status200OK, "ETag", "string", "De ETag van de response.")]
[SwaggerResponseHeader(StatusCodes.Status200OK, "x-correlation-id", "string", "Correlatie identificator van de response.")]
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(AddressSearchResponseExamples))]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status403Forbidden, typeof(ForbiddenResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status429TooManyRequests, typeof(TooManyRequestsResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamplesV2))]
[HttpCacheValidation(NoCache = true, MustRevalidate = true, ProxyRevalidate = true)]
[HttpCacheExpiration(CacheLocation = CacheLocation.Private, MaxAge = DefaultListCaching, NoStore = true, NoTransform = true)]
public async Task<IActionResult> SearchAddresses(
[FromQuery] string? query,
[FromQuery] string? municipalityOrPostalName,
[FromQuery] int? limit,
[FromServices] SearchAddressesToggle searchAddressesToggle,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] IOptions<AddressOptionsV2> responseOptions,
CancellationToken cancellationToken = default)
{
if (!searchAddressesToggle.FeatureEnabled)
{
return NotFound();
}

limit = int.Max(MaxSearchLimit, limit ?? DefaultSearchLimit);
var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => CreateBackendListRequest(
limit,
query,
municipalityOrPostalName);

var value = await GetFromBackendAsync(
contentFormat.ContentType,
BackendRequest,
CreateDefaultHandleBadRequest(),
cancellationToken);

return BackendListResponseResult.Create(value, Request.Query, responseOptions.Value.VolgendeUrl);
}

private static RestRequest CreateBackendListRequest(
int? limit,
string? query,
string? municipalityOrPostalName)
{
var filter = new AddressSearchFilter
{
Query = query,
MunicipalityOrPostalName = municipalityOrPostalName
};

return new RestRequest("adressen/zoeken")
.AddPagination(0, limit)
.AddFiltering(filter);
}
}
}
2 changes: 0 additions & 2 deletions src/Public.Api/Address/Oslo/AddressOsloController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Public.Api.Address.Oslo
using Be.Vlaanderen.Basisregisters.Api;
using Common.Infrastructure;
using Common.Infrastructure.Controllers;
using Common.Infrastructure.Controllers.Attributes;
using FeatureToggle;
using Infrastructure.Configuration;
using Infrastructure.Swagger;
Expand All @@ -20,7 +19,6 @@ namespace Public.Api.Address.Oslo
[AdvertiseApiVersions(Version.V2)]
[ApiRoute("")]
[ApiExplorerSettings(GroupName = "Adressen")]
[ApiProduces(EndpointType.Oslo)]
public partial class AddressOsloController : RegistryApiController<AddressOsloController>
{
protected override string NotFoundExceptionMessage => "Onbestaand adres.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class FeatureToggleOptions
public bool CorrectRegularizationAddress { get; set; }
public bool CorrectDeregulationAddress { get; set; }
public bool CorrectRemovalAddress { get; set; }
public bool SearchAddresses { 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 @@ -351,6 +351,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.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 SearchAddressesToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.SearchAddresses))
.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 @@ -443,6 +443,7 @@
"CorrectDeregulationAddress": false,
"CorrectRemovalAddress": false,
"ReaddressStreetNameAddresses": false,
"SearchAddresses": false,

"PlanBuilding": false,
"MergeBuilding": false,
Expand Down

0 comments on commit f8f5326

Please sign in to comment.