Skip to content

Commit

Permalink
feat: add road v2 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored Mar 29, 2024
1 parent 9fc1aae commit 34b2390
Show file tree
Hide file tree
Showing 61 changed files with 2,128 additions and 86 deletions.
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ nuget Be.Vlaanderen.Basisregisters.IntegrationDb.SuspiciousCases.Api.Abstraction
nuget Be.Vlaanderen.Basisregisters.Build.Pipeline 7.2.4

nuget Be.Vlaanderen.Basisregisters.Auth.AcmIdm 2.0.0
nuget Be.Vlaanderen.Basisregisters.Api 21.1.0
nuget Be.Vlaanderen.Basisregisters.Api 22.0.0

// DataDog To Remove after testing
nuget Be.Vlaanderen.Basisregisters.DataDog.Tracing 6.0.0
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NUGET
Be.Vlaanderen.Basisregisters.AggregateSource (9.0.1)
Be.Vlaanderen.Basisregisters.EventHandling (>= 5.0)
SqlStreamStore (>= 1.2)
Be.Vlaanderen.Basisregisters.Api (21.1)
Be.Vlaanderen.Basisregisters.Api (22.0)
Asp.Versioning.Mvc.ApiExplorer (>= 8.0)
Autofac (>= 8.0)
Autofac.Extensions.DependencyInjection (>= 9.0)
Expand Down
2 changes: 1 addition & 1 deletion src/Public.Api/ErrorDetail/ErrorDetailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Public.Api.ErrorDetail
using Microsoft.Extensions.Configuration;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;

[ApiVersion(Version.Current)]
[ApiVersion(Version.V1)]
[ApiVersion(Version.V2)]
[AdvertiseApiVersions(Version.CurrentAdvertised)]
[ApiRoute("")]
Expand Down
12 changes: 7 additions & 5 deletions src/Public.Api/Infrastructure/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
builder
.AddMvcOptions(options =>
{
options.Conventions.Add(new FeatureToggleConvention(_configuration));
//GRAR-1877
options.ModelBindingMessageProvider.SetAttemptedValueIsInvalidAccessor((value,fieldName) => $"De waarde '{value}' is ongeldig voor {fieldName}.");

Expand Down Expand Up @@ -272,9 +271,13 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.RewriteAcceptTypeForProblemDetail();
}
},
ActionModelConventions = { new ApiDocumentationHiddenConvention() }
ActionModelConventions =
{
new ApiVisibleActionModelConvention(),
new FeatureToggleConvention(_configuration)
}
}
.EnableJsonErrorActionFilterOption())
.EnableJsonErrorActionFilterOption())

.AddHttpClient()

Expand Down Expand Up @@ -408,8 +411,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.AddSingleton(c => new DetailSuspiciousCasesToggle(c.GetRequiredService<IOptions<FeatureToggleOptions>>().Value.GetSuspiciousCases));

services
.RemoveAll<IApiControllerSpecification>()
.TryAddEnumerable(ServiceDescriptor.Transient<IApiControllerSpecification, ToggledApiControllerSpec>());
.RemoveAll<IApiControllerSpecification>();

var containerBuilder = new ContainerBuilder();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Public.Api.Infrastructure.Swagger;

using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;

public class ApiVisibleActionModelConvention : IActionModelConvention
{
public void Apply(ActionModel action)
{
var actionIgnored = action.ActionMethod.GetCustomAttribute<ApiExplorerSettingsAttribute>()?.IgnoreApi == true;
if (actionIgnored)
{
return;
}

var isVisible = action.Controller.ControllerType
.GetCustomAttributes<ApiVisibleAttribute>(true)
.Select(x => x.Visible)
.FirstOrDefault();

action.ApiExplorer.IsVisible = isVisible;
}
}
13 changes: 13 additions & 0 deletions src/Public.Api/Infrastructure/Swagger/ApiVisibleAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Public.Api.Infrastructure.Swagger
{
using System;

[AttributeUsage(AttributeTargets.Class)]
public class ApiVisibleAttribute : Attribute
{
public bool Visible { get; }

public ApiVisibleAttribute() : this(true) { }
public ApiVisibleAttribute(bool visible) => Visible = visible;
}
}
43 changes: 0 additions & 43 deletions src/Public.Api/Infrastructure/Swagger/ToggledApiControllerSpec.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Public.Api/Infrastructure/Version/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Public.Api.Infrastructure.Version
public static class Version
{
// TODO: remove current when road is v2
public const string Current = "1.0";
public const string V1 = "1.0";
public const string CurrentAdvertised = "2.0";
public const string V2 = "2.0";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Public.Api/Road/Changes/ChangeFeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Public.Api.Road.Changes
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Logging;

[ApiVersion(Version.Current)]
[ApiVersion(Version.V1)]
[AdvertiseApiVersions(Version.CurrentAdvertised)]
[ApiRoute("")]
[ApiExplorerSettings(GroupName = "Activiteit")]
Expand Down
32 changes: 32 additions & 0 deletions src/Public.Api/Road/Changes/V2/ChangeFeedController-GetContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Public.Api.Road.Changes.V2
{
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;
using System.Threading;
using System.Threading.Tasks;

public partial class ChangeFeedControllerV2
{
[HttpGet("wegen/activiteit/gebeurtenis/{id}/inhoud", Name = nameof(GetContentV2))]
public async Task<IActionResult> GetContentV2(
[FromRoute] long? id,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "changefeed/entry/{id}/content")
.AddParameter(nameof(id), id, ParameterType.UrlSegment);

var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);
return new BackendResponseResult(response);
}
}
}
34 changes: 34 additions & 0 deletions src/Public.Api/Road/Changes/V2/ChangeFeedController-GetHead.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Public.Api.Road.Changes.V2
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;

public partial class ChangeFeedControllerV2
{
[HttpGet("wegen/activiteit/begin", Name = nameof(GetHeadV2))]
public async Task<IActionResult> GetHeadV2(
[FromQuery] int? maxEntryCount,
[FromQuery] string? filter,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "changefeed/head")
.AddParameter(nameof(maxEntryCount), maxEntryCount, ParameterType.QueryString)
.AddParameter(nameof(filter), filter, ParameterType.QueryString);

var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);
return new BackendResponseResult(response);
}
}
}
36 changes: 36 additions & 0 deletions src/Public.Api/Road/Changes/V2/ChangeFeedController-GetNext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Public.Api.Road.Changes.V2
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;

public partial class ChangeFeedControllerV2
{
[HttpGet("wegen/activiteit/volgende", Name = nameof(GetNextV2))]
public async Task<IActionResult> GetNextV2(
[FromQuery] long? afterEntry,
[FromQuery] int? maxEntryCount,
[FromQuery] string? filter,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "changefeed/next")
.AddParameter(nameof(maxEntryCount), maxEntryCount, ParameterType.QueryString)
.AddParameter(nameof(afterEntry), afterEntry, ParameterType.QueryString)
.AddParameter(nameof(filter), filter, ParameterType.QueryString);

var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);
return new BackendResponseResult(response);
}
}
}
36 changes: 36 additions & 0 deletions src/Public.Api/Road/Changes/V2/ChangeFeedController-GetPrevious.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Public.Api.Road.Changes.V2
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;

public partial class ChangeFeedControllerV2
{
[HttpGet("wegen/activiteit/vorige", Name = nameof(GetPreviousV2))]
public async Task<IActionResult> GetPreviousV2(
[FromQuery] long? beforeEntry,
[FromQuery] int? maxEntryCount,
[FromQuery] string? filter,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "changefeed/previous")
.AddParameter(nameof(maxEntryCount), maxEntryCount, ParameterType.QueryString)
.AddParameter(nameof(beforeEntry), beforeEntry, ParameterType.QueryString)
.AddParameter(nameof(filter), filter, ParameterType.QueryString);

var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);
return new BackendResponseResult(response);
}
}
}
35 changes: 35 additions & 0 deletions src/Public.Api/Road/Changes/V2/ChangeFeedControllerV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Public.Api.Road.Changes.V2
{
using Asp.Versioning;
using Autofac.Features.AttributeFilters;
using Be.Vlaanderen.Basisregisters.Api;
using Common.Infrastructure;
using FeatureToggle;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Logging;
using Public.Api.Infrastructure.Configuration;
using Public.Api.Infrastructure.Swagger;
using Public.Api.Infrastructure.Version;

[ApiVersion(Version.V2)]
[AdvertiseApiVersions(Version.CurrentAdvertised)]
[ApiRoute("")]
[ApiExplorerSettings(GroupName = "Activiteit")]
[ApiOrder(ApiOrder.Road.ChangeFeed)]
public partial class ChangeFeedControllerV2 : RoadRegistryApiController<ChangeFeedControllerV2>
{
protected override string NotFoundExceptionMessage => "Onbestaande activiteit.";
protected override string GoneExceptionMessage => "Verwijderde activiteit.";

public ChangeFeedControllerV2(
IHttpContextAccessor httpContextAccessor,
IActionContextAccessor actionContextAccessor,
[KeyFilter(RegistryKeys.Road)] IRestClient restClient,
[KeyFilter(RegistryKeys.Road)] IFeatureToggle cacheToggle,
ConnectionMultiplexerProvider redis,
ILogger<ChangeFeedControllerV2> logger)
: base(httpContextAccessor, redis, logger, restClient, cacheToggle, actionContextAccessor) { }
}
}
2 changes: 1 addition & 1 deletion src/Public.Api/Road/Downloads/DownloadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Public.Api.Road.Downloads
using System.Net.Http;
using Asp.Versioning;

[ApiVersion(Version.Current)]
[ApiVersion(Version.V1)]
[AdvertiseApiVersions(Version.CurrentAdvertised)]
[ApiRoute("")]
[ApiExplorerSettings(GroupName = "Download")]
Expand Down
Loading

0 comments on commit 34b2390

Please sign in to comment.