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

22 odpc minimaal document in publicatieformulier #48

Merged
merged 19 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Mvc;

namespace ODPC.Features.Documenten.DocumentDetail
{
[ApiController]
public class DocumentDetailController: ControllerBase
{
[HttpGet("api/v1/documenten/{uuid:guid}")]
public IActionResult Get(Guid uuid)
{
return DocumentenMock.Documenten.TryGetValue(uuid, out var document)
? Ok(document)
: NotFound();
}
}
}
24 changes: 24 additions & 0 deletions ODPC.Server/Features/Documenten/DocumentenMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ODPC.Features.Publicaties;

namespace ODPC.Features.Documenten
{
public static class DocumentenMock
{
public static readonly Dictionary<Guid, PublicatieDocument> Documenten = new PublicatieDocument[]
{
new()
{
Uuid = Guid.NewGuid(),
Publicatie = PublicatiesMock.Publicaties.Keys.First(),
OfficieleTitel = "Belangrijk document",
VerkorteTitel = "Document",
Omschrijving = "",
Creatiedatum = new DateOnly(2024, 09, 23),
Bestandsformaat = "DOCX",
Bestandsnaam = "belangrijk.docx",
Bestandsomvang = 100000
}
}
.ToDictionary(x => x.Uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;

namespace ODPC.Features.Documenten.DocumentenOverzicht
{
[ApiController]
public class DocumentenOverzichtController : ControllerBase
{
[HttpGet("api/v1/documenten")]
public IActionResult Get([FromQuery] Guid publicatie)
{
var documenten = DocumentenMock.Documenten.Values
.Where(x=> x.Publicatie == publicatie)
.OrderBy(x=> x.Creatiedatum)
.ToList();

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

namespace ODPC.Features.Documenten.InitialiseerDocument
{
[ApiController]
public class InitialiseerDocumentController : ControllerBase
{
[HttpPost("api/v1/documenten")]
public IActionResult Post(PublicatieDocument document)
{
document.Uuid = Guid.NewGuid();
document.Creatiedatum = DateOnly.FromDateTime(DateTime.Now);

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

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
}
];

DocumentenMock.Documenten[document.Uuid] = document;
return Ok(document);
}
}
}
23 changes: 23 additions & 0 deletions ODPC.Server/Features/Documenten/PublicatieDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ODPC.Features.Documenten
{
public class PublicatieDocument
{
public Guid Uuid { get; set; }
public Guid Publicatie { get; set; }
public required string OfficieleTitel { get; set; }
public string? VerkorteTitel { get; set; }
public string? Omschrijving { 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 class Bestandsdeel
{
public required string Url { get; set; }
public required int Volgnummer { get; set; }
public required double Omvang { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;

namespace ODPC.Features.Documenten.UploadBestandsdeel
{
[ApiController]
public class UploadBestandsdeelController : ControllerBase
{
[HttpPut("api/v1/documenten/{uuid:guid}/bestandsdelen/{volgnummer:int}")]
public IActionResult Put(Guid uuid, int volgnummer)
{
return NoContent();
}
}
}
9 changes: 9 additions & 0 deletions ODPC.Server/Features/Formats/Format.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ODPC.Features.Formats
{
public class Format
{
public required string Identifier { get; set; }
public required string Name { get; set; }
public required string MimeType { get; set; }
}
}
28 changes: 28 additions & 0 deletions ODPC.Server/Features/Formats/FormatsMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ODPC.Features.Formats
{
public static class FormatsMock
{
public static readonly Dictionary<string, Format> Formats = new Format[]
{
new() { Name = "7z", MimeType = "application/x-7z-compressed", Identifier = "a81129a3-ec70-40f3-8eb6-fc94e97ef865" },
new() { Name = "CSV", MimeType = "text/csv", Identifier = "6bdd2631-b5d5-472a-b336-9cc643822f0a" },
new() { Name = "Excel XLS", MimeType = "application/vnd.ms-excel", Identifier = "822928f7-73f0-45d3-b1a0-4f3a3dbc361a" },
new() { Name = "Excel XLSX", MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Identifier = "fd16ded8-f013-4ca7-ba21-ee3ca36a6054" },
new() { Name = "HTML", MimeType = "text/html", Identifier = "bf16a8af-f40b-4e36-96e3-0bdd5d6f5316" },
new() { Name = "ODF", MimeType = "application/vnd.oasis.opendocument.formula", Identifier = "26a3df9c-290c-40a4-98cb-387842816698" },
new() { Name = "ODP", MimeType = "application/vnd.oasis.opendocument.presentation", Identifier = "8b31aa20-d284-4540-aca4-222e1394c1d5" },
new() { Name = "ODS", MimeType = "application/vnd.oasis.opendocument.spreadsheet", Identifier = "837abc18-616f-4e82-945b-fe78ab939860" },
new() { Name = "ODT", MimeType = "application/vnd.oasis.opendocument.text", Identifier = "53b7d662-4413-4901-a3a4-6c129fcb93c1" },
new() { Name = "PDF", MimeType = "application/pdf", Identifier = "a8836b30-8b25-4af6-9b35-e68e4f644c59" },
new() { Name = "TXT", MimeType = "text/plain", Identifier = "549c6a31-6274-4b51-8528-fa9de141681e" },
new() { Name = "PPSX", MimeType = "application/vnd.openxmlformats-officedocument.presentationml.slideshow", Identifier = "ff7cf4ad-372f-4996-b6af-5bf8c5b178d8" },
new() { Name = "PPT", MimeType = "application/vnd.ms-powerpoint", Identifier = "580e3592-c5b2-40d0-ab7a-0c626c8e171a" },
new() { Name = "PPTX", MimeType = "application/vnd.openxmlformats-officedocument.presentationml.presentation", Identifier = "fc188a40-f0bf-415f-a339-fd7520b531f8" },
new() { Name = "PPS", MimeType = "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", Identifier = "65298a3a-346d-4614-9fee-028f532ed8bc" },
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;

namespace ODPC.Features.Formats.FormatsOverzicht
{
[ApiController]
public class FormatsOverzichtController : ControllerBase
{
[HttpGet("/api/v1/formats")]
public IActionResult Get()
{
return Ok(FormatsMock.Formats.Values.OrderBy(x => x.Name));
}
}
}
94 changes: 72 additions & 22 deletions odpc.client/mock/api.mock.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { type MockHandler } from "vite-plugin-mock-server";
import type { Publicatie } from "@/features/publicatie/types";
import { randomUUID } from "crypto";
import type { Publicatie, MimeTypes, PublicatieDocument } from "@/features/publicatie/types";

import publicatiesJson from "./publicaties.json";
import documentenJson from "./documenten.json";
import mimeTypesJson from "./mime-types.json";

const getIndex = (url: string | undefined) => +(url?.substring(url.lastIndexOf("/") + 1) || 0); // ...

const publicaties: Publicatie[] = [
{
uuid: "0",
officieleTitel:
"Openbaarheid en Verantwoording: De Impact van de Wet open overheid op Bestuurlijke Transparantie",
verkorteTitel: "Openbaarheid en Verantwoording",
omschrijving: "",
creatiedatum: "2024-08-24"
},
{
uuid: "1",
officieleTitel: "Inzicht voor Iedereen: Toepassing en Resultaten van de Wet open overheid",
verkorteTitel: "Inzicht voor Iedereen",
omschrijving: "",
creatiedatum: "2024-05-02"
}
];
const publicaties: Publicatie[] = publicatiesJson;
const documenten: PublicatieDocument[] = documentenJson;
const mimeTypes: MimeTypes[] = mimeTypesJson;

const mocks: MockHandler[] = [
{
pattern: "/api-mock/publicaties",
pattern: "/api-mock/v1/publicaties",
method: "GET",
handle: (_req, res) => {
res.setHeader("Content-Type", "application/json");
Expand All @@ -32,7 +23,7 @@ const mocks: MockHandler[] = [
}
},
{
pattern: "/api-mock/publicaties",
pattern: "/api-mock/v1/publicaties",
method: "POST",
handle: (req, res) => {
res.setHeader("Content-Type", "application/json");
Expand All @@ -50,7 +41,7 @@ const mocks: MockHandler[] = [
}
},
{
pattern: "/api-mock/publicaties/*",
pattern: "/api-mock/v1/publicaties/*",
method: "GET",
handle: (req, res) => {
res.setHeader("Content-Type", "application/json");
Expand All @@ -59,7 +50,7 @@ const mocks: MockHandler[] = [
}
},
{
pattern: "/api-mock/publicaties/*",
pattern: "/api-mock/v1/publicaties/*",
method: "PUT",
handle: (req, res) => {
res.setHeader("Content-Type", "application/json");
Expand All @@ -72,6 +63,65 @@ const mocks: MockHandler[] = [
setTimeout(() => res.end(JSON.stringify(publicatie)), 500);
});
}
},
{
pattern: "/api-mock/v1/documenten/*",
method: "GET",
handle: (_req, res) => {
res.setHeader("Content-Type", "application/json");

setTimeout(() => res.end(JSON.stringify(documenten[0])), 500);
}
},
{
pattern: "/api-mock/v1/documenten/**",
method: "POST",
handle: (req, res) => {
res.setHeader("Content-Type", "application/json");

req.on("data", (bodyString: string) => {
const body: any = JSON.parse(bodyString);
const { bestandsomvang } = body;

const uuid = randomUUID();
const halve = bestandsomvang / 2;
const firstSize = Math.ceil(halve);
const secondSize = Math.floor(halve);

const responseBody = {
...documenten[0],
bestandsdelen: [
{
url: `/api-mock/v1/documenten/${uuid}/bestandsdelen/1`,
volgnummer: 0,
omvang: firstSize
},
{
url: `/api-mock/v1/documenten/${uuid}/bestandsdelen/2`,
volgnummer: 1,
omvang: secondSize
}
]
};

setTimeout(() => res.end(JSON.stringify(responseBody)), 500);
});
}
},
{
pattern: "/api-mock/v1/documenten/*/bestandsdelen/*",
method: "PUT",
handle: (_req, res) => {
setTimeout(() => res.end(), 500);
}
},
{
pattern: "/api-mock/v1/formats",
method: "GET",
handle: (_req, res) => {
res.setHeader("Content-Type", "application/json");
setTimeout(() => res.end(JSON.stringify(mimeTypes)), 500);
}
}
];

Expand Down
13 changes: 13 additions & 0 deletions odpc.client/mock/documenten.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"uuid": "0",
"publicatie": "0",
"officieleTitel": "Belangrijk document",
"verkorteTitel": "Document",
"omschrijving": "",
"creatiedatum": "2024-09-23",
"bestandsnaam": "belangrijk.docx",
"bestandsformaat": "DOCX",
"bestandsomvang": 100000
}
]
Loading