Skip to content

Commit

Permalink
Merge pull request #101 from GeneriekPublicatiePlatformWoo/68-odpc-pu…
Browse files Browse the repository at this point in the history
…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
felixcicatt authored Nov 25, 2024
2 parents b0c1744 + 2464b6c commit f96b89f
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 516 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;
using ODPC.Authentication;

namespace ODPC.Features.Documenten.DocumentBijwerken
{
[ApiController]
public class DocumentBijwerkenController(IOdrcClientFactory clientFactory) : ControllerBase
public class DocumentBijwerkenController(IOdrcClientFactory clientFactory, OdpcUser user) : ControllerBase
{
[HttpPut("api/{apiVersion}/documenten/{uuid:guid}")]
public async Task<IActionResult> Put(string apiVersion, Guid uuid, PublicatieDocument document, CancellationToken token)
[HttpPut("api/{version}/documenten/{uuid:guid}")]
public async Task<IActionResult> Put(string version, Guid uuid, PublicatieDocument document, CancellationToken token)
{
using var client = clientFactory.Create("Document bijwerken");
var url = "/api/" + apiVersion + "/documenten/" + uuid;

var response = await client.PutAsJsonAsync(url, document, token);
var url = $"/api/{version}/documenten/{uuid}";

response.EnsureSuccessStatusCode();
// document ophalen
using var getResponse = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token);

var viewModel = await response.Content.ReadFromJsonAsync<PublicatieDocument>(token);
if (!getResponse.IsSuccessStatusCode)
{
return StatusCode(502);
}

var json = await getResponse.Content.ReadFromJsonAsync<PublicatieDocument>(token);

if (json?.Eigenaar?.identifier != user.Id)
{
return NotFound();
}

// document bijwerken
using var putResponse = await client.PutAsJsonAsync(url, document, token);

putResponse.EnsureSuccessStatusCode();

var viewModel = await putResponse.Content.ReadFromJsonAsync<PublicatieDocument>(token);

return Ok(viewModel);
}
Expand Down
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");
}
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
using System.Text.Json.Nodes;
using System.Net;
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;
using ODPC.Authentication;

namespace ODPC.Features.Documenten.DocumentenOverzicht
{
[ApiController]
public class DocumentenOverzichtController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpGet("api/{apiVersion}/documenten")]
public async Task<IActionResult> Get(string apiVersion, [FromQuery] string publicatie, string? page, CancellationToken token)
[HttpGet("api/{version}/documenten")]
public async Task<IActionResult> Get(
string version,
[FromQuery] string publicatie,
OdpcUser user,
CancellationToken token,
[FromQuery] string? page = "1")
{
// documenten ophalen uit het ODRC
using var client = clientFactory.Create("Documenten ophalen");
var url = "/api/" + apiVersion + "/documenten?publicatie=" + publicatie + "&page=" + page;

var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>(url, token);
var url = $"/api/{version}/documenten?publicatie={publicatie}&eigenaar={WebUtility.UrlEncode(user.Id)}&page={page}";

using var response = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token);

if (!response.IsSuccessStatusCode)
{
return StatusCode(502);
}

var json = await response.Content.ReadFromJsonAsync<PagedResponseModel<JsonNode>>(token);

return Ok(json);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using ODPC.Apis.Odrc;
using ODPC.Features.Publicaties;

namespace ODPC.Features.Documenten.InitialiseerDocument
{
[ApiController]
public class InitialiseerDocumentController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpPost("api/{apiVersion}/documenten")]
public async Task<IActionResult> Post(string apiVersion, PublicatieDocument document, CancellationToken token)
[HttpPost("api/{version}/documenten")]
public async Task<IActionResult> Post(string version, PublicatieDocument document, CancellationToken token)
{
using var client = clientFactory.Create("Initialiseer document");
var url = "/api/" + apiVersion + "/documenten";

var response = await client.PostAsJsonAsync(url, document, token);
var url = $"/api/{version}/documenten";

using var response = await client.PostAsJsonAsync(url, document, token);

response.EnsureSuccessStatusCode();

Expand Down
7 changes: 7 additions & 0 deletions ODPC.Server/Features/Documenten/PublicatieDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class PublicatieDocument
public required string OfficieleTitel { get; set; }
public string? VerkorteTitel { get; set; }
public string? Omschrijving { get; set; }
public Eigenaar? Eigenaar { get; set; }
public string? Publicatiestatus { get; set; }
public DateOnly Creatiedatum { get; set; }
public required string Bestandsnaam { get; set; }
Expand All @@ -16,6 +17,12 @@ public class PublicatieDocument
public List<Bestandsdeel>? Bestandsdelen { get; set; }
}

public class Eigenaar
{
public string? identifier { get; set; }
public string? weergaveNaam { get; set; }
}

public class Bestandsdeel
{
public required string Url { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace ODPC.Features.Documenten.UploadBestandsdeel
[RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
public class UploadBestandsdeelController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpPut("api/{apiVersion}/documenten/{docUuid:guid}/bestandsdelen/{partUuid:guid}")]
public async Task<IActionResult> Put(string apiVersion, Guid docUuid, Guid partUuid, CancellationToken token)
[HttpPut("api/{version}/documenten/{docUuid:guid}/bestandsdelen/{partUuid:guid}")]
public async Task<IActionResult> Put(string version, Guid docUuid, Guid partUuid, CancellationToken token)
{
var form = await Request.ReadFormAsync(token);

Expand All @@ -25,9 +25,10 @@ public async Task<IActionResult> Put(string apiVersion, Guid docUuid, Guid partU
content.Add(fileContent, "inhoud", file.FileName);

using var client = clientFactory.Create("Upload bestandsdeel");
var url = "/api/" + apiVersion + "/documenten/" + docUuid + "/bestandsdelen/" + partUuid;

var response = await client.PutAsync(url, content, token);
var url = $"/api/{version}/documenten/{docUuid}/bestandsdelen/{partUuid}";

using var response = await client.PutAsync(url, content, token);

response.EnsureSuccessStatusCode();

Expand Down
6 changes: 4 additions & 2 deletions ODPC.Server/Features/Formats/FormatsMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static class FormatsMock
new() { Name = "RTF", MimeType = "application/rtf", Identifier = "63026476-5d40-424e-a113-b02ed7fba760" },
new() { Name = "DOC", MimeType = "application/msword", Identifier = "26ccc5e3-acf2-4251-9618-46321e2b9d36" },
new() { Name = "DOCX", MimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Identifier = "ae0ea877-3207-4a97-b5df-bf552bc9b895" },
new() { Name = "ZIP", MimeType = "application/zip", Identifier = "f879f55e-a9c2-4779-96b2-288d6359d86b" }
}.ToDictionary(x => x.Identifier);
new() { Name = "ZIP", MimeType = "application/zip", Identifier = "f879f55e-a9c2-4779-96b2-288d6359d86b" },
new() { Name = "ZIP Win v1", MimeType = "application/zip-compressed", Identifier = "f879f55e-a9c2-4779-96b2-288d6359d86b" },
new() { Name = "ZIP Win v2", MimeType = "application/x-zip-compressed", Identifier = "f879f55e-a9c2-4779-96b2-288d6359d86b" }
}.ToDictionary(x => x.MimeType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ namespace ODPC.Features.Informatiecategorieen.AlleInformatiecategorieen
[ApiController]
public class InformatiecategorieenController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpGet("api/{apiVersion}/informatiecategorieen")]
public async Task<IActionResult> Get(string apiVersion, [FromQuery] string? page, CancellationToken token)
[HttpGet("api/{version}/informatiecategorieen")]
public async Task<IActionResult> Get(string version, CancellationToken token, [FromQuery] string? page = "1")
{
// infocategorien ophalen uit het ODRC
using var client = clientFactory.Create("Informatiecategorieen ophalen");
var url = "/api/" + apiVersion + "/informatiecategorieen?page=" + page;
var url = $"/api/{version}/informatiecategorieen?page={page}";

var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>(url, token);
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token);

if (!response.IsSuccessStatusCode)
{
return StatusCode(502);
}

var json = await response.Content.ReadFromJsonAsync<PagedResponseModel<JsonNode>>(token);

return Ok(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace ODPC.Features.Informatiecategorieen.MijnInformatiecategorieen
[ApiController]
public class MijnInformatiecategorieenController(IOdrcClientFactory clientFactory, IGebruikerWaardelijstItemsService waardelijstItemsService) : ControllerBase
{
[HttpGet("api/{apiVersion}/mijn-informatiecategorieen")]
public async IAsyncEnumerable<JsonObject> Get(string apiVersion, [EnumeratorCancellation] CancellationToken token)
[HttpGet("api/{version}/mijn-informatiecategorieen")]
public async IAsyncEnumerable<JsonObject> Get(string version, [EnumeratorCancellation] CancellationToken token)
{
var categorieen = await waardelijstItemsService.GetAsync(token);

if (categorieen.Count == 0) yield break;

using var client = clientFactory.Create("Eigen informatiecategorieen ophalen");
var url = "/api/" + apiVersion + "/informatiecategorieen";
var url = $"/api/{version}/informatiecategorieen";

// omdat we zelf moeten filteren obv van de waardelijstitems waar de gebruiker toegang toe heeft,
// kunnen we geen paginering gebruiker. we lopen door alle pagina's van de ODRC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ namespace ODPC.Features.Organisaties.AlleOrganisaties
[ApiController]
public class OrganisatiesController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpGet("api/{apiVersion}/organisaties")]
public async Task<IActionResult> Get(string apiVersion, [FromQuery] string? page, CancellationToken token)
[HttpGet("api/{version}/organisaties")]
public async Task<IActionResult> Get(string version, CancellationToken token, [FromQuery] string? page = "1")
{
// organisaties ophalen uit het ODRC
using var client = clientFactory.Create("Organisaties ophalen");
var url = "/api/" + apiVersion + "/organisaties?page=" + page;
var url = $"/api/{version}/organisaties?page={page}";

var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>(url, token);
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token);

if (!response.IsSuccessStatusCode)
{
return StatusCode(502);
}

var json = await response.Content.ReadFromJsonAsync<PagedResponseModel<JsonNode>>(token);

return Ok(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace ODPC.Features.Organisaties.MijnOrganisaties
{
public class MijnOrganisatiesController(IOdrcClientFactory clientFactory, IGebruikerWaardelijstItemsService waardelijstItemsService) : ControllerBase
{
[HttpGet("api/{apiVersion}/mijn-organisaties")]
public async IAsyncEnumerable<JsonObject> Get(string apiVersion, [EnumeratorCancellation] CancellationToken token)
[HttpGet("api/{version}/mijn-organisaties")]
public async IAsyncEnumerable<JsonObject> Get(string version, [EnumeratorCancellation] CancellationToken token)
{
var organisaties = await waardelijstItemsService.GetAsync(token);

if (organisaties.Count == 0) yield break;

using var client = clientFactory.Create("Eigen organisaties ophalen");
var url = "/api/" + apiVersion + "/organisaties";
var url = $"/api/{version}/organisaties";

// omdat we zelf moeten filteren obv van de waardelijstitems waar de gebruiker toegang toe heeft,
// kunnen we geen paginering gebruiker. we lopen door alle pagina's van de ODRC
Expand Down
13 changes: 11 additions & 2 deletions ODPC.Server/Features/Publicaties/Publicatie.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ODPC.Features.Publicaties
using ODPC.Features.Documenten;

namespace ODPC.Features.Publicaties
{
public class Publicatie
{
Expand All @@ -8,8 +10,15 @@ public class Publicatie
public string? OfficieleTitel { get; set; }
public string? VerkorteTitel { get; set; }
public string? Omschrijving { get; set; }
public Eigenaar? Eigenaar { get; set; }
public string? Publicatiestatus { get; set; }
public DateTime Registratiedatum { get; set; }
public string? Status { get; set; }
public List<string>? InformatieCategorieen { get; set; }
}

public class Eigenaar
{
public string? identifier { get; set; }
public string? weergaveNaam { get; set; }
}
}
Loading

0 comments on commit f96b89f

Please sign in to comment.