Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42 odpc minimaal document versturen naar registratiecomponent #100

Merged
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;

namespace ODPC.Features.Documenten.DocumentBijwerken
{
[ApiController]
public class DocumentBijwerkenController : ControllerBase
public class DocumentBijwerkenController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpPut("api/v1/documenten/{uuid:guid}")]
public IActionResult Put(Guid uuid, PublicatieDocument document)
public async Task<IActionResult> Put(Guid uuid, PublicatieDocument document, CancellationToken token)
{
DocumentenMock.Documenten[document.Uuid] = document;
return Ok(document);
using var client = clientFactory.Create("Document bijwerken");
var response = await client.PutAsJsonAsync("/api/v1/documenten/" + uuid, document, token);

response.EnsureSuccessStatusCode();

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

return Ok(viewModel);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading;
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;

namespace ODPC.Features.Documenten.DocumentDownload
{
public class DocumentDownloadController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpGet("api/v1/documenten/{uuid:guid}/download")]
public async Task<IActionResult> Get(Guid uuid, CancellationToken token)
{
using var client = clientFactory.Create("Document downloaden");
var response = await client.GetAsync("/api/v1/documenten/" + uuid + "/download", token);

response.EnsureSuccessStatusCode();

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);

return File(fileStream, contentType, fileName);
}
}
}
25 changes: 0 additions & 25 deletions ODPC.Server/Features/Documenten/DocumentenMock.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;

namespace ODPC.Features.Documenten.DocumentenOverzicht
{
[ApiController]
public class DocumentenOverzichtController : ControllerBase
public class DocumentenOverzichtController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpGet("api/v1/documenten")]
public IActionResult Get([FromQuery] Guid publicatie)
public async Task<IActionResult> Get([FromQuery] string publicatie, string? page, CancellationToken token)
{
var documenten = DocumentenMock.Documenten.Values
.Where(x=> x.Publicatie == publicatie)
.OrderBy(x=> x.Creatiedatum)
.ToList();
// documenten ophalen uit het ODRC
using var client = clientFactory.Create("Documenten ophalen");
var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>("/api/v1/documenten?publicatie=" + publicatie + "&page=" + page, token);

if (json != null)
{
json.Previous = UrlHelper.GetPathAndQuery(json.Previous);
json.Next = UrlHelper.GetPathAndQuery(json.Next);
}

return Ok(documenten);
return Ok(json);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;

namespace ODPC.Features.Documenten.InitialiseerDocument
{
[ApiController]
public class InitialiseerDocumentController : ControllerBase
public class InitialiseerDocumentController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpPost("api/v1/documenten")]
public IActionResult Post(PublicatieDocument document)
public async Task<IActionResult> Post(PublicatieDocument document, CancellationToken token)
{
document.Uuid = Guid.NewGuid();
document.Creatiedatum = DateOnly.FromDateTime(DateTime.Now);
using var client = clientFactory.Create("Initialiseer document");
var response = await client.PostAsJsonAsync("/api/v1/documenten", document, token);

var halve = document.Bestandsomvang / 2;
var firstSize = Math.Ceiling(halve);
var secondSize = Math.Floor(halve);
response.EnsureSuccessStatusCode();

document.Bestandsdelen =
[
new()
{
Omvang = firstSize,
Url = $"/api/v1/documenten/{document.Uuid}/bestandsdelen/1",
Volgnummer = 0
},
new()
{
Omvang = secondSize,
Url = $"/api/v1/documenten/{document.Uuid}/bestandsdelen/2",
Volgnummer = 1
}
];
var viewModel = await response.Content.ReadFromJsonAsync<PublicatieDocument>(token);

DocumentenMock.Documenten[document.Uuid] = document;
return Ok(document);
return Ok(viewModel);
}
}
}
3 changes: 2 additions & 1 deletion ODPC.Server/Features/Documenten/PublicatieDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
public class PublicatieDocument
{
public Guid Uuid { get; set; }
public string? Identifier { get; set; }
public Guid Publicatie { get; set; }
public required string OfficieleTitel { get; set; }
public string? VerkorteTitel { get; set; }
public string? Omschrijving { get; set; }
public string? Publicatiestatus { get; set; }
public DateOnly Creatiedatum { get; set; }
public required string Bestandsnaam { get; set; }
public required string Bestandsformaat { get; set; }
public required double Bestandsomvang { get; set; }
public List<Bestandsdeel>? Bestandsdelen { get; set; }
public string? Status { get; set; }
}

public class Bestandsdeel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Reflection.Metadata;
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;

namespace ODPC.Features.Documenten.UploadBestandsdeel
{
[ApiController]
public class UploadBestandsdeelController : ControllerBase
[DisableRequestSizeLimit]
public class UploadBestandsdeelController(IOdrcClientFactory clientFactory) : ControllerBase
{
[HttpPut("api/v1/documenten/{uuid:guid}/bestandsdelen/{volgnummer:int}")]
public IActionResult Put(Guid uuid, int volgnummer)
[HttpPut("api/v1/documenten/{docUuid:guid}/bestandsdelen/{partUuid:guid}")]
public async Task<IActionResult> Put(Guid docUuid, Guid partUuid, CancellationToken token)
{
var form = await Request.ReadFormAsync(token);

if (form.Files.Count == 0)
{
return BadRequest("No file uploaded");
}

var file = form.Files[0];
var content = new MultipartFormDataContent();
var fileContent = new StreamContent(file.OpenReadStream());

content.Add(fileContent, "inhoud", file.FileName);

using var client = clientFactory.Create("Upload bestandsdeel");
var response = await client.PutAsync("/api/v1/documenten/" + docUuid + "/bestandsdelen/" + partUuid, content, token);

response.EnsureSuccessStatusCode();

return NoContent();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ public class InformatiecategorieenController(IOdrcClientFactory clientFactory) :
[HttpGet("api/v1/informatiecategorieen")]
public async Task<IActionResult> Get([FromQuery] string? page, CancellationToken token)
{
//infocategorien ophalen uit het ODRC
using var client = clientFactory.Create("Alle informatiecategorieen ophalen");
// infocategorien ophalen uit het ODRC
using var client = clientFactory.Create("Informatiecategorieen ophalen");
var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>("/api/v1/informatiecategorieen?page=" + page, token);

if (json != null)
{
json.Previous = GetPathAndQuery(json.Previous);
json.Next = GetPathAndQuery(json.Next);
json.Previous = UrlHelper.GetPathAndQuery(json.Previous);
json.Next = UrlHelper.GetPathAndQuery(json.Next);
}

return Ok(json);
}

private static string? GetPathAndQuery(string? url) => Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)
? uri.PathAndQuery
: url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ public async Task<IActionResult> Get([FromQuery] string? page, CancellationToken
// organisaties ophalen uit het ODRC
using var client = clientFactory.Create("Organisaties ophalen");
var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>("/api/v1/organisaties?page=" + page, token);

if (json != null)
{
json.Previous = GetPathAndQuery(json.Previous);
json.Next = GetPathAndQuery(json.Next);
json.Previous = UrlHelper.GetPathAndQuery(json.Previous);
json.Next = UrlHelper.GetPathAndQuery(json.Next);
}

return Ok(json);
}

private static string? GetPathAndQuery(string? url) => Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)
? uri.PathAndQuery
: url;
}
}
9 changes: 9 additions & 0 deletions ODPC.Server/Features/UrlHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ODPC.Features
{
public static class UrlHelper
{
public static string? GetPathAndQuery(string? url) => Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)
? uri.PathAndQuery
: url;
}
}
8 changes: 4 additions & 4 deletions odpc.client/src/features/publicatie/PublicatieDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

<document-form
v-else
v-model:documenten="documenten"
v-model:files="files"
@removeDocument="removeDocument"
v-model:documenten="documenten"
:disabled="initialStatus === PublicatieStatus.ingetrokken"
/>
</section>
Expand Down Expand Up @@ -101,6 +100,7 @@ const error = computed(
() =>
!!publicatieError.value ||
!!documentenError.value ||
!!documentError.value ||
!!waardelijstenUserError.value ||
forbidden.value
);
Expand All @@ -122,9 +122,9 @@ const {
loadingDocumenten,
documentenError,
loadingDocument,
documentError,
uploadingFile,
submitDocumenten,
removeDocument
submitDocumenten
} =
// Get associated docs by uuid prop when existing pub, so no need to wait for pub fetch.
// Publicatie.uuid is used when new pub and associated docs: docs submit waits for pub submit/publicatie.uuid.
Expand Down
Loading