-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from GeneriekPublicatiePlatformWoo/68-odpc-pu…
…blicaties-en-documenten-ophalen-publiceren-en-intrekken-uit-het-odrc 68 odpc publicaties en documenten ophalen publiceren en intrekken uit het odrc
- Loading branch information
Showing
32 changed files
with
316 additions
and
516 deletions.
There are no files selected for viewing
32 changes: 25 additions & 7 deletions
32
ODPC.Server/Features/Documenten/DocumentBijwerken/DocumentBijwerkenController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 15 additions & 13 deletions
28
ODPC.Server/Features/Documenten/DocumentDownload/DocumentDownloadController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
using System.Threading; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
using ODPC.Authentication; | ||
|
||
namespace ODPC.Features.Documenten.DocumentDownload | ||
{ | ||
public class DocumentDownloadController(IOdrcClientFactory clientFactory) : ControllerBase | ||
public class DocumentDownloadController(IOdrcClientFactory clientFactory, OdpcUser user) : ControllerBase | ||
{ | ||
[HttpGet("api/{apiVersion}/documenten/{uuid:guid}/download")] | ||
public async Task<IActionResult> Get(string apiVersion, Guid uuid, CancellationToken token) | ||
[HttpGet("api/{version}/documenten/{uuid:guid}/download")] | ||
public async Task<IActionResult> Get(string version, Guid uuid, CancellationToken token) | ||
{ | ||
using var client = clientFactory.Create("Document downloaden"); | ||
var url = "/api/" + apiVersion + "/documenten/" + uuid + "/download"; | ||
using var client = clientFactory.Create("Document ophalen"); | ||
|
||
var response = await client.GetAsync(url, token); | ||
var url = $"/api/{version}/documenten/{uuid}"; | ||
|
||
response.EnsureSuccessStatusCode(); | ||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token); | ||
|
||
var contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream"; | ||
var fileName = response.Content.Headers.ContentDisposition?.FileName?.Trim('"') ?? "woo_document"; | ||
var fileStream = await response.Content.ReadAsStreamAsync(token); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
return StatusCode(502); | ||
} | ||
|
||
return File(fileStream, contentType, fileName); | ||
var json = await response.Content.ReadFromJsonAsync<PublicatieDocument>(token); | ||
|
||
return json?.Eigenaar?.identifier != user.Id ? NotFound() : new DocumentDownloadResult(Request.Path, "Document downloaden"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ODPC.Server/Features/Documenten/DocumentDownload/DocumentDownloadResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Documenten.DocumentDownload | ||
{ | ||
public class DocumentDownloadResult(string path, string reason) : IActionResult | ||
{ | ||
public async Task ExecuteResultAsync(ActionContext context) | ||
{ | ||
var response = context.HttpContext.Response; | ||
var token = context.HttpContext.RequestAborted; | ||
|
||
using var client = context.HttpContext.RequestServices.GetRequiredService<IOdrcClientFactory>().Create(reason); | ||
using var httpResponse = await client.GetAsync(path, HttpCompletionOption.ResponseContentRead, token); ; | ||
|
||
response.StatusCode = (int)httpResponse.StatusCode; | ||
response.Headers.ContentLength = httpResponse.Content.Headers.ContentLength; | ||
response.Headers.ContentDisposition = httpResponse.Content.Headers.ContentDisposition?.ToString(); | ||
response.Headers.ContentType = httpResponse.Content.Headers.ContentType?.ToString(); | ||
|
||
await httpResponse.Content.CopyToAsync(response.Body, token); | ||
} | ||
} | ||
} |
25 changes: 20 additions & 5 deletions
25
ODPC.Server/Features/Documenten/DocumentenOverzicht/DocumentenOverzichtController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
ODPC.Server/Features/Documenten/InitialiseerDocument/InitialiseerDocumentController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.