Skip to content

Commit

Permalink
feat: GAWR-5717 add road presigned endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
rikdepeuter authored Jan 15, 2025
1 parent 1be5f48 commit 9a3fefa
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 58 deletions.
19 changes: 8 additions & 11 deletions src/Public.Api/Road/Extracts/V2/ExtractController-CreateJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ namespace Public.Api.Road.Extracts.V2
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Public.Api.Infrastructure;
using RestSharp;
using RoadRegistry.BackOffice.Abstractions.Jobs;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
Expand All @@ -23,7 +22,6 @@ public partial class ExtractControllerV2
[HttpPost("wegen/extract/download/{downloadId}/jobs", Name = nameof(RoadExtractCreateJobV2))]
public async Task<IActionResult> RoadExtractCreateJobV2(
[FromRoute] string downloadId,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] RoadJobsToggle featureToggle,
CancellationToken cancellationToken = default)
Expand All @@ -33,19 +31,18 @@ public async Task<IActionResult> RoadExtractCreateJobV2(
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => new RestRequest($"extracts/download/{downloadId}/jobs", Method.Post)
.AddHeaderAuthorization(actionContextAccessor);

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

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
return new BackendResponseResult(value);

RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Post, "extracts/download/{downloadId}/jobs")
.AddParameter("downloadId", downloadId, ParameterType.UrlSegment);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Public.Api.Road.Extracts.V2
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;
using RoadRegistry.BackOffice.Api.Extracts;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
namespace Public.Api.Road.Extracts.V2
{
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure.Controllers.Attributes;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Public.Api.Infrastructure;
using RestSharp;
using RoadRegistry.BackOffice.Api.Extracts;

public partial class ExtractControllerV2
{
[ApiKeyAuth("Road", AllowAuthorizationHeader = true)]
[HttpPost("wegen/extract/downloadaanvragen/perbestand")]
[RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue, ValueLengthLimit = int.MaxValue)]
public async Task<ActionResult> PostDownloadRequestByFileV2(
[FromBody] DownloadExtractByFileRequestBody body,
DownloadExtractByFileRequestBody body,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Post, "extracts/downloadrequests/byfile")
.AddJsonBodyOrEmpty(body);

var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
Expand All @@ -31,6 +29,27 @@ RestRequest BackendRequest() =>
cancellationToken: cancellationToken);

return new BackendResponseResult(response);

RestRequest BackendRequest()
{
var request = CreateBackendRestRequest(Method.Post, "extracts/downloadrequests/byfile");

request.AddParameter(nameof(body.Description), body.Description, ParameterType.GetOrPost);
request.AddParameter(nameof(body.IsInformative), body.IsInformative, ParameterType.GetOrPost);
foreach (var file in body.Files)
{
request.AddFile(nameof(body.Files), () =>
{
var copyStream = new MemoryStream();
file.OpenReadStream().CopyTo(copyStream);
copyStream.Position = 0;
return copyStream;
}, file.FileName);
}
request.AddHeader("Content-Type", "multipart/form-data");

return request;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ namespace Public.Api.Road.Extracts.V2
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure.Controllers.Attributes;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using RestSharp;

public partial class ExtractControllerV2
{
[ApiKeyAuth("Road", AllowAuthorizationHeader = true)]
[HttpGet("wegen/extract/download/{downloadId}/presignedurl")]
public async Task<ActionResult> GetDownloadPreSignedUrlForExtract(
[FromRoute]string downloadId,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromRoute] string downloadId,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
Expand All @@ -28,11 +25,11 @@ public async Task<ActionResult> GetDownloadPreSignedUrlForExtract(
problemDetailsHelper,
cancellationToken: cancellationToken);

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
return new BackendResponseResult(value);

RestRequest BackendRequest() => new RestRequest("extracts/download/{downloadId}/presignedurl", Method.Get)
.AddParameter("downloadId", downloadId, ParameterType.UrlSegment)
.AddHeaderAuthorization(actionContextAccessor);
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "extracts/download/{downloadId}/presignedurl")
.AddParameter("downloadId", downloadId, ParameterType.UrlSegment);
}
}
}
15 changes: 6 additions & 9 deletions src/Public.Api/Road/Grb/V2/GrbController-ExtractByContour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ namespace Public.Api.Road.Grb.V2
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using RestSharp;
using RoadRegistry.BackOffice.Abstractions.Extracts;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
Expand All @@ -21,25 +19,24 @@ public partial class GrbControllerV2
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[HttpPost("wegen/grb/extracts/bycontour", Name = nameof(ExtractByContour))]
[HttpPost("wegen/grb/extract/percontour", Name = nameof(ExtractByContour))]
public async Task<IActionResult> ExtractByContour(
[FromBody] DownloadExtractRequestBody body,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
var value = await GetFromBackendWithBadRequestAsync(
var response = await GetFromBackendWithBadRequestAsync(
AcceptType.Json,
BackendRequest,
CreateDefaultHandleBadRequest(),
problemDetailsHelper,
cancellationToken: cancellationToken);

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
return new BackendResponseResult(response);

RestRequest BackendRequest() => new RestRequest("grb/extracts/bycontour", Method.Post)
.AddJsonBodyOrEmpty(body)
.AddHeaderAuthorization(actionContextAccessor);
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Post, "grb/extracts/bycontour")
.AddJsonBodyOrEmpty(body);
}
}
}
9 changes: 4 additions & 5 deletions src/Public.Api/Road/Grb/V2/GrbController-UploadForDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public partial class GrbControllerV2
[HttpPost("wegen/grb/download/{downloadId}/upload", Name = nameof(UploadForDownload))]
public async Task<IActionResult> UploadForDownload(
[FromRoute] string downloadId,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
Expand All @@ -36,11 +35,11 @@ public async Task<IActionResult> UploadForDownload(
problemDetailsHelper,
cancellationToken: cancellationToken);

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
return new BackendResponseResult(value);

RestRequest BackendRequest() => new RestRequest("grb/download/{downloadId}/upload", Method.Post)
.AddParameter("downloadId", downloadId, ParameterType.UrlSegment)
.AddHeaderAuthorization(actionContextAccessor);
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Post, "grb/download/{downloadId}/upload")
.AddParameter("downloadId", downloadId, ParameterType.UrlSegment);
}
}
}
18 changes: 7 additions & 11 deletions src/Public.Api/Road/Uploads/V2/UploadController-CreateJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ namespace Public.Api.Road.Uploads.V2
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Public.Api.Infrastructure;
using RestSharp;
using RoadRegistry.BackOffice.Abstractions.Jobs;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
Expand All @@ -22,7 +21,6 @@ public partial class UploadControllerV2
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[HttpPost("wegen/upload/jobs", Name = nameof(RoadUploadCreateJobV2))]
public async Task<IActionResult> RoadUploadCreateJobV2(
[FromServices] IActionContextAccessor actionContextAccessor,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
[FromServices] RoadJobsToggle featureToggle,
CancellationToken cancellationToken = default)
Expand All @@ -32,19 +30,17 @@ public async Task<IActionResult> RoadUploadCreateJobV2(
return NotFound();
}

var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

RestRequest BackendRequest() => new RestRequest("upload/jobs", Method.Post)
.AddHeaderAuthorization(actionContextAccessor);

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

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());
return new BackendResponseResult(value);

RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Post, "upload/jobs");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ namespace Public.Api.Road.Uploads.V2
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Common.Infrastructure.Controllers.Attributes;
using Common.Infrastructure.Extensions;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using RestSharp;

public partial class UploadControllerV2
{
[ApiKeyAuth("Road", AllowAuthorizationHeader = true)]
[HttpGet("wegen/upload/{identifier}/presignedurl")]
public async Task<ActionResult> GetDownloadPreSignedUrlForUpload(
[FromRoute]string identifier,
[FromServices] IActionContextAccessor actionContextAccessor,
[FromRoute] string identifier,
[FromServices] ProblemDetailsHelper problemDetailsHelper,
CancellationToken cancellationToken = default)
{
Expand All @@ -30,9 +27,9 @@ public async Task<ActionResult> GetDownloadPreSignedUrlForUpload(

return new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice());

RestRequest BackendRequest() => new RestRequest("upload/{identifier}/presignedurl", Method.Get)
.AddParameter("identifier", identifier, ParameterType.UrlSegment)
.AddHeaderAuthorization(actionContextAccessor);
RestRequest BackendRequest() =>
CreateBackendRestRequest(Method.Get, "upload/{identifier}/presignedurl")
.AddParameter("identifier", identifier, ParameterType.UrlSegment);
}
}
}

0 comments on commit 9a3fefa

Please sign in to comment.