Skip to content

Commit

Permalink
fix: suspicious cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Jan 30, 2024
1 parent b345065 commit ceeca47
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 4 deletions.
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ nuget Be.Vlaanderen.Basisregisters.PublicServiceRegistry.Api.Backoffice 2.1.1 c
nuget Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice 3.66.6 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice.Api 3.66.6 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice.Abstractions 3.66.6 copy_content_to_output_dir: always
nuget Be.Vlaanderen.Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions 1.3.3 copy_content_to_output_dir: always

nuget Be.Vlaanderen.Basisregisters.Build.Pipeline 6.0.5

Expand Down
2 changes: 2 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ NUGET
Be.Vlaanderen.Basisregisters.Crab (>= 3.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions (1.3.3) - copy_content_to_output_dir: always
Be.Vlaanderen.Basisregisters.Api (>= 20.0)
Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple (4.9.1) - copy_content_to_output_dir: always
AWSSDK.Core (>= 3.7.106.8)
AWSSDK.SQS (>= 3.7.100.101)
Expand Down
14 changes: 14 additions & 0 deletions src/Common/Infrastructure/FeatureToggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,18 @@ public class GetRoadOrganizationsToggle : IFeatureToggle

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

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

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

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

public DetailSuspiciousCasesToggle(bool featureEnabled) => FeatureEnabled = featureEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ public class FeatureToggleOptions
public bool UnlinkRoadSegmentStreetName { get; set; }
public bool GetRoadSegment { get; set; }
public bool GetRoadOrganizations { get; set; }
public bool GetSuspiciousCases { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public static class RegistryKeys
public const string ParcelBackOffice = "ParcelRegistryBackOffice";
public const string Road = "RoadRegistry";
public const string TicketingService = "TicketingService";
public const string SuspiciousCases = "SuspiciousCases";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Public.Api.Infrastructure.Configuration
{
using Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions;

public class SuspiciousCasesOptionsV2 : ResponseOptions, IRegistryOptions
{
public SyndicationOptions Syndication { get; set; }
}
}
7 changes: 5 additions & 2 deletions src/Public.Api/Infrastructure/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
typeof(PublicServiceRegistry.Api.Backoffice.Infrastructure.Startup).GetTypeInfo().Assembly.GetName().Name,
typeof(RoadRegistry.BackOffice.Api.Infrastructure.Startup).GetTypeInfo().Assembly.GetName().Name,
typeof(RoadRegistry.BackOffice.Abstractions.EndpointRequest).GetTypeInfo().Assembly.GetName().Name,
typeof(Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions.List.SuspiciousCasesListResponse).GetTypeInfo().Assembly.GetName().Name,
typeof(Be.Vlaanderen.Basisregisters.GrAr.Common.NodaHelpers).GetTypeInfo().Assembly.GetName().Name,
typeof(Be.Vlaanderen.Basisregisters.GrAr.Edit.GmlConstants).GetTypeInfo().Assembly.GetName().Name,
typeof(Be.Vlaanderen.Basisregisters.GrAr.Legacy.Identificator).GetTypeInfo().Assembly.GetName().Name,
Expand Down Expand Up @@ -318,6 +319,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.ConfigureRegistryOptions<BuildingOptionsV2>(_configuration.GetSection("ApiConfiguration:BuildingRegistryV2"))
.ConfigureRegistryOptions<ParcelOptions>(_configuration.GetSection("ApiConfiguration:ParcelRegistry"))
.ConfigureRegistryOptions<ParcelOptionsV2>(_configuration.GetSection("ApiConfiguration:ParcelRegistryV2"))
.ConfigureRegistryOptions<SuspiciousCasesOptionsV2>(_configuration.GetSection("ApiConfiguration:SuspiciousCases"))
.Configure<FeatureToggleOptions>(_configuration.GetSection(FeatureToggleOptions.ConfigurationKey))
.Configure<ExcludedRouteModelOptions>(_configuration.GetSection("ExcludedRoutes"))
.AddSingleton(c => new FeedsVisibleToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.IsFeedsVisible))
Expand Down Expand Up @@ -399,7 +401,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.AddSingleton(c => new UnlinkRoadSegmentStreetNameToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.UnlinkRoadSegmentStreetName))
.AddSingleton(c => new GetRoadSegmentToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.GetRoadSegment))
.AddSingleton(c => new GetRoadOrganizationsToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.GetRoadOrganizations))
;
.AddSingleton(c => new ListSuspiciousCasesToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.GetSuspiciousCases))
.AddSingleton(c => new DetailSuspiciousCasesToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.GetSuspiciousCases));

services
.RemoveAll<IApiControllerSpecification>()
Expand Down Expand Up @@ -677,7 +680,7 @@ public void Configure(

private static bool AssemblyNameIsRegistryAssembly(string? name)
{
return name != null && (name.Contains("Registry.Api") || name.Contains("RoadRegistry"));
return name != null && (name.Contains("Registry.Api") || name.Contains("RoadRegistry") || name.Contains("IntegrationDb"));
}

private string GetApiLeadingText(ApiVersionDescription description, bool isFeedsVisibleToggle, bool isProposeStreetName)
Expand Down
4 changes: 3 additions & 1 deletion src/Public.Api/Infrastructure/Swagger/ApiOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public static class Road
public const int Status = CrabHouseNumber + 100;

public const int AddressRepresentation = Status + 100;

public const int SuspiciousCases = AddressRepresentation + 100;
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
Expand Down Expand Up @@ -130,7 +132,7 @@ public static string Sort(ApiDescription desc)
.GetCustomAttributes<ApiOrderAttribute>(true)
.Select(x => x.Order)
.ToList();

return apiGroupNames.Count == 0
? int.MaxValue.ToString()
: apiGroupNames.First().ToString();
Expand Down
1 change: 1 addition & 0 deletions src/Public.Api/Public.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.PublicServiceRegistry.Api.Backoffice\content\PublicServiceRegistry.Api.Backoffice.xml" CopyToOutputDirectory="Always" />
<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice.Abstractions\content\RoadRegistry.BackOffice.Abstractions.xml" CopyToOutputDirectory="Always" />
<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.RoadRegistry.BackOffice.Api\content\RoadRegistry.BackOffice.Api.xml" CopyToOutputDirectory="Always" />
<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions\content\Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions.xml" CopyToOutputDirectory="Always" />

<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.GrAr.Common\lib\net6.0\Be.Vlaanderen.Basisregisters.GrAr.Common.xml" CopyToOutputDirectory="Always" />
<Content Include="..\..\packages\Be.Vlaanderen.Basisregisters.GrAr.Edit\lib\net6.0\Be.Vlaanderen.Basisregisters.GrAr.Edit.xml" CopyToOutputDirectory="Always" />
Expand Down
116 changes: 116 additions & 0 deletions src/Public.Api/SuspiciousCases/SuspiciousCasesController-Detail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
namespace Public.Api.SuspiciousCases
{
using System.Threading;
using System.Threading.Tasks;
using Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions.Detail;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Extensions;
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;
using ValidationProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails;

public partial class SuspiciousCasesController
{
/// <summary>
/// Vraag een verdacht geval op.
/// </summary>
/// <param name="type">Het type van het verdachte geval.</param>
/// <param name="offset">Nulgebaseerde index van de eerste instantie die teruggegeven wordt.</param>
/// <param name="limit">Aantal instanties dat teruggegeven wordt.</param>
/// <param name="nisCode">Filter op de NIS-code van het verdacht geval.</param>
/// <param name="actionContextAccessor"></param>
/// <param name="problemDetailsHelper"></param>
/// <param name="responseOptions"></param>
/// <param name="suspiciousCasesToggle"></param>
/// <param name="cancellationToken"></param>
/// <response code="200">Als de opvraging van het verdacht geval gelukt is.</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="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("verdachte-gevallen/{type}", Name = nameof(DetailSuspiciousCases))]
[ApiOrder(ApiOrder.SuspiciousCases + 2)]
[ProducesResponseType(typeof(SuspiciousCasesDetailResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(SuspiciousCasesDetailResponseExample))]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status401Unauthorized, typeof(UnauthorizedOAuthResponseExamplesV2))]
[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> DetailSuspiciousCases(
[FromRoute] int type,
[FromQuery] int? offset,
[FromQuery] int? limit,
[FromQuery] string nisCode,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] IOptions<SuspiciousCasesOptionsV2> responseOptions,
[FromServices] DetailSuspiciousCasesToggle suspiciousCasesToggle,
CancellationToken cancellationToken = default)
{
if (!suspiciousCasesToggle.FeatureEnabled)
{
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => CreateBackendDetailRequest(
type,
offset,
limit,
nisCode,
actionContextAccessor);

var nextUrl = responseOptions.Value.SuspiciousCasesTypeNextUrl.Replace("{type}", type.ToString());

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


return BackendListResponseResult.Create(value, Request.Query, nextUrl);
}

private static RestRequest CreateBackendDetailRequest(
int type,
int? offset,
int? limit,
string nisCode,
IActionContextAccessor actionContextAccessor)
{
var filter = new SuspiciousCasesDetailFilter
{
NisCode = nisCode,
};

return new RestRequest("verdachte-gevallen/{type}")
.AddParameter("type", type, ParameterType.UrlSegment)
.AddPagination(offset, limit)
.AddFiltering(filter)
.AddHeaderAuthorization(actionContextAccessor);
}
}
}
95 changes: 95 additions & 0 deletions src/Public.Api/SuspiciousCases/SuspiciousCasesController-List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
namespace Public.Api.SuspiciousCases
{
using System.Threading;
using System.Threading.Tasks;
using Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstractions.List;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Infrastructure.Swagger;
using Marvin.Cache.Headers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using RestSharp;
using Swashbuckle.AspNetCore.Filters;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
using ValidationProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails;

public partial class SuspiciousCasesController
{
/// <summary>
/// Vraag een lijst met verdachte gevallen op.
/// </summary>
/// <param name="nisCode">Filter op de NIS-code van het verdachte geval.</param>
/// <param name="actionContextAccessor"></param>
/// <param name="problemDetailsHelper"></param>
/// <param name="suspiciousCasesToggle"></param>
/// <param name="cancellationToken"></param>
/// <response code="200">Als de opvraging van een lijst met verdachte gevallen gelukt is.</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="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("verdachte-gevallen", Name = nameof(ListSuspiciousCases))]
[ApiOrder(ApiOrder.SuspiciousCases + 1)]
[ProducesResponseType(typeof(SuspiciousCasesListResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(SuspiciousCasesListResponseExample))]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(BadRequestResponseExamplesV2))]
[SwaggerResponseExample(StatusCodes.Status401Unauthorized, typeof(UnauthorizedOAuthResponseExamplesV2))]
[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> ListSuspiciousCases(
[FromQuery] string nisCode,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] ListSuspiciousCasesToggle suspiciousCasesToggle,
CancellationToken cancellationToken = default)
{
if (!suspiciousCasesToggle.FeatureEnabled)
{
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => CreateBackendListRequest(
nisCode,
actionContextAccessor);

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

return new BackendResponseResult(value);
}

private static RestRequest CreateBackendListRequest(
string nisCode,
IActionContextAccessor actionContextAccessor)
{
var filter = new SuspiciousCasesListFilter
{
NisCode = nisCode,
};

return new RestRequest("verdachte-gevallen")
.AddFiltering(filter)
.AddHeaderAuthorization(actionContextAccessor);
}
}
}
Loading

0 comments on commit ceeca47

Please sign in to comment.