Skip to content

Commit

Permalink
feat: implement postalcode filter on list streetname
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy committed Oct 9, 2023
1 parent 4b211e3 commit d8d42b9
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace StreetNameRegistry.Api.Legacy.Infrastructure.Modules
using Autofac.Extensions.DependencyInjection;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.DependencyInjection;
using Consumer.Read.Postal.Infrastructure.Modules;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -35,7 +36,8 @@ protected override void Load(ContainerBuilder builder)
.RegisterModule(new LegacyModule(_configuration, _services, _loggerFactory));

builder
.RegisterModule(new SyndicationModule(_configuration, _services, _loggerFactory));
.RegisterModule(new SyndicationModule(_configuration, _services, _loggerFactory))
.RegisterModule(new ConsumerPostalModule(_configuration, _services, _loggerFactory));

builder
.RegisterType<ProblemDetailsHelper>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace StreetNameRegistry.Api.Legacy.Infrastructure.Modules
{
using Autofac;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Consumer.Read.Postal;
using FeatureToggles;
using MediatR;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -36,13 +37,15 @@ protected override void Load(ContainerBuilder builder)
new ListHandlerV2(
c.Resolve<LegacyContext>(),
c.Resolve<SyndicationContext>(),
c.Resolve<ConsumerPostalContext>(),
c.Resolve<IOptions<ResponseOptions>>());
}

return (IRequestHandler<ListRequest, StreetNameListResponse>)
new ListHandler(
c.Resolve<LegacyContext>(),
c.Resolve<SyndicationContext>(),
c.Resolve<ConsumerPostalContext>(),
c.Resolve<IOptions<ResponseOptions>>());
}).InstancePerLifetimeScope();

Expand Down Expand Up @@ -72,13 +75,16 @@ protected override void Load(ContainerBuilder builder)
return (IRequestHandler<CountRequest, TotaalAantalResponse>)
new CountHandlerV2(
c.Resolve<LegacyContext>(),
c.Resolve<SyndicationContext>());
c.Resolve<SyndicationContext>(),
c.Resolve<ConsumerPostalContext>());
}

return (IRequestHandler<CountRequest, TotaalAantalResponse>)
new CountHandler(
c.Resolve<LegacyContext>(),
c.Resolve<SyndicationContext>());
c.Resolve<SyndicationContext>(),
c.Resolve<ConsumerPostalContext>());

}).InstancePerLifetimeScope();

builder.Register(c =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.Count
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api.Search.Pagination;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Consumer.Read.Postal;
using Microsoft.EntityFrameworkCore;
using Projections.Legacy;
using Projections.Legacy.StreetNameList;
Expand All @@ -15,11 +16,13 @@ public sealed class CountHandler : CountHandlerBase
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _postalContext;

public CountHandler(LegacyContext legacyContext, SyndicationContext syndicationContext)
public CountHandler(LegacyContext legacyContext, SyndicationContext syndicationContext, ConsumerPostalContext postalContext)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_postalContext = postalContext;
}

public override async Task<TotaalAantalResponse> Handle(CountRequest request, CancellationToken cancellationToken)
Expand All @@ -29,7 +32,7 @@ public override async Task<TotaalAantalResponse> Handle(CountRequest request, Ca
return new TotaalAantalResponse
{
Aantal = request.Filtering.ShouldFilter
? await new StreetNameListQuery(_legacyContext, _syndicationContext)
? await new StreetNameListQuery(_legacyContext, _syndicationContext, _postalContext)
.Fetch<StreetNameListItem, StreetNameListItem>(request.Filtering, request.Sorting, pagination)
.Items
.CountAsync(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.Count
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api.Search.Pagination;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Consumer.Read.Postal;
using Microsoft.EntityFrameworkCore;
using Projections.Legacy;
using Projections.Legacy.StreetNameListV2;
Expand All @@ -14,11 +15,13 @@ public sealed class CountHandlerV2 : CountHandlerBase
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _postalContext;

public CountHandlerV2(LegacyContext legacyContext, SyndicationContext syndicationContext)
public CountHandlerV2(LegacyContext legacyContext, SyndicationContext syndicationContext, ConsumerPostalContext postalContext)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_postalContext = postalContext;
}

public override async Task<TotaalAantalResponse> Handle(CountRequest request, CancellationToken cancellationToken)
Expand All @@ -28,7 +31,7 @@ public override async Task<TotaalAantalResponse> Handle(CountRequest request, Ca
return
new TotaalAantalResponse
{
Aantal = await new StreetNameListQueryV2(_legacyContext, _syndicationContext)
Aantal = await new StreetNameListQueryV2(_legacyContext, _syndicationContext, _postalContext)
.Fetch<StreetNameListItemV2, StreetNameListItemV2>(request.Filtering, request.Sorting, pagination)
.Items
.CountAsync(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.List
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Consumer.Read.Postal;
using Convertors;
using Infrastructure.Options;
using Microsoft.EntityFrameworkCore;
Expand All @@ -19,21 +20,24 @@ public sealed class ListHandler : ListHandlerBase
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _PostalContext;
private readonly IOptions<ResponseOptions> _responseOptions;

public ListHandler(
LegacyContext legacyContext,
SyndicationContext syndicationContext,
ConsumerPostalContext postalContext,
IOptions<ResponseOptions> responseOptions)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_PostalContext = postalContext;
_responseOptions = responseOptions;
}

public override async Task<StreetNameListResponse> Handle(ListRequest request, CancellationToken cancellationToken)
{
var streetNameQuery = new StreetNameListQuery(_legacyContext, _syndicationContext)
var streetNameQuery = new StreetNameListQuery(_legacyContext, _syndicationContext, _PostalContext)
.Fetch<StreetNameListItem, StreetNameListItem>(request.Filtering, request.Sorting, request.Pagination);

var pagedStreetNames = await streetNameQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.List
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Consumer.Read.Postal;
using Convertors;
using Infrastructure.Options;
using Microsoft.EntityFrameworkCore;
Expand All @@ -19,21 +20,25 @@ public sealed class ListHandlerV2 : ListHandlerBase
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _postalContext;

private readonly IOptions<ResponseOptions> _responseOptions;

public ListHandlerV2(
LegacyContext legacyContext,
SyndicationContext syndicationContext,
ConsumerPostalContext postalContext,
IOptions<ResponseOptions> responseOptions)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_postalContext = postalContext;
_responseOptions = responseOptions;
}

public override async Task<StreetNameListResponse> Handle(ListRequest request, CancellationToken cancellationToken)
{
var streetNameQuery = new StreetNameListQueryV2(_legacyContext, _syndicationContext)
var streetNameQuery = new StreetNameListQueryV2(_legacyContext, _syndicationContext, _postalContext)
.Fetch<StreetNameListItemV2, StreetNameListItemV2>(request.Filtering, request.Sorting, request.Pagination);

var pagedStreetNames = await streetNameQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.Query
using Be.Vlaanderen.Basisregisters.Api.Search.Sorting;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy.Straatnaam;
using Consumer.Read.Postal;
using Convertors;
using Microsoft.EntityFrameworkCore;
using Projections.Legacy;
Expand All @@ -18,13 +19,15 @@ public sealed class StreetNameListQuery : Query<StreetNameListItem, StreetNameFi
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _postalContext;

protected override ISorting Sorting => new StreetNameSorting();

public StreetNameListQuery(LegacyContext legacyContext, SyndicationContext syndicationContext)
public StreetNameListQuery(LegacyContext legacyContext, SyndicationContext syndicationContext, ConsumerPostalContext postalContext)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_postalContext = postalContext;
}

protected override IQueryable<StreetNameListItem> Filter(FilteringHeader<StreetNameFilter> filtering)
Expand Down Expand Up @@ -89,6 +92,15 @@ protected override IQueryable<StreetNameListItem> Filter(FilteringHeader<StreetN
}
}

if (filtering.Filter.PostalCode is not null)
{
var postalConsumerItem = _postalContext.PostalConsumerItems.Find(new object[] {filtering.Filter.PostalCode});
if (postalConsumerItem?.NisCode != null)
{
streetNames = streetNames.Where(m => m.NisCode == postalConsumerItem.NisCode);
}
}

return streetNames;
}

Expand Down Expand Up @@ -138,5 +150,6 @@ public sealed class StreetNameFilter
public string NameEnglish { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string? NisCode { get; set; } = string.Empty;
public string? PostalCode { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace StreetNameRegistry.Api.Legacy.StreetName.Query
using Be.Vlaanderen.Basisregisters.Api.Search.Sorting;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy.Straatnaam;
using Consumer.Read.Postal;
using Convertors;
using Microsoft.EntityFrameworkCore;
using Projections.Legacy;
Expand All @@ -17,13 +18,15 @@ public sealed class StreetNameListQueryV2 : Query<StreetNameListItemV2, StreetNa
{
private readonly LegacyContext _legacyContext;
private readonly SyndicationContext _syndicationContext;
private readonly ConsumerPostalContext _PostalContext;

protected override ISorting Sorting => new StreetNameSorting();

public StreetNameListQueryV2(LegacyContext legacyContext, SyndicationContext syndicationContext)
public StreetNameListQueryV2(LegacyContext legacyContext, SyndicationContext syndicationContext, ConsumerPostalContext postalContext)
{
_legacyContext = legacyContext;
_syndicationContext = syndicationContext;
_PostalContext = postalContext;
}

protected override IQueryable<StreetNameListItemV2> Filter(FilteringHeader<StreetNameFilter> filtering)
Expand Down Expand Up @@ -107,6 +110,15 @@ protected override IQueryable<StreetNameListItemV2> Filter(FilteringHeader<Stree
}
}

if (filtering.Filter.PostalCode is not null)
{
var postalConsumerItem = _PostalContext.PostalConsumerItems.Find(new object[] {filtering.Filter.PostalCode});
if (postalConsumerItem?.NisCode != null)
{
streetNames = streetNames.Where(m => m.NisCode == postalConsumerItem.NisCode);
}
}

return streetNames;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StreetNameRegistry.Consumer.Read.Postal\StreetNameRegistry.Consumer.Read.Postal.csproj" />
<ProjectReference Include="..\StreetNameRegistry.Projections.Legacy\StreetNameRegistry.Projections.Legacy.csproj" />
<ProjectReference Include="..\StreetNameRegistry.Projections.Syndication\StreetNameRegistry.Projections.Syndication.csproj" />
<ProjectReference Include="..\StreetNameRegistry\StreetNameRegistry.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion src/StreetNameRegistry.Api.Legacy/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"Events": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;",
"LegacyProjections": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;",
"SyndicationProjections": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;",
"LegacyProjectionsAdmin": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;"
"LegacyProjectionsAdmin": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;",
"ConsumerPostal": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.StreetNameRegistry;Trusted_Connection=True;TrustServerCertificate=True;"
},

"DataDog": {
Expand Down

0 comments on commit d8d42b9

Please sign in to comment.