From 52af299f0344c5316a3f9502ef05cd7453495a96 Mon Sep 17 00:00:00 2001 From: Felix Cornelissen Date: Mon, 23 Sep 2024 11:28:32 +0200 Subject: [PATCH 1/2] chore: mock maken voor publicaties op backend --- .../Features/Publicaties/PublicatiesMock.cs | 70 +++++++++++++++++++ .../features/publicatie/PublicatieDetails.vue | 2 +- .../publicatie/PublicatiesOverview.vue | 2 +- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 ODPC.Server/Features/Publicaties/PublicatiesMock.cs diff --git a/ODPC.Server/Features/Publicaties/PublicatiesMock.cs b/ODPC.Server/Features/Publicaties/PublicatiesMock.cs new file mode 100644 index 0000000..f3f7f77 --- /dev/null +++ b/ODPC.Server/Features/Publicaties/PublicatiesMock.cs @@ -0,0 +1,70 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ODPC.Features.Publicaties +{ + public class Publicatie + { + public Guid Uuid { get; set; } + public string? OfficieleTitel { get; set; } + public string? VerkorteTitel { get; set; } + public string? Omschrijving { get; set; } + public DateOnly Creatiedatum { get; set; } + public string? Status { get; set; } + } + + [ApiController] + [Route("api/v1/publicaties")] + public class PublicatiesMock: ControllerBase + { + private static readonly Dictionary s_publicaties = new Publicatie[] + { + new() + { + Uuid = Guid.NewGuid(), + OfficieleTitel = "Openbaarheid en Verantwoording: De Impact van de Wet open overheid op Bestuurlijke Transparantie", + VerkorteTitel = "Openbaarheid en Verantwoording", + Omschrijving = "", + Creatiedatum = new DateOnly(2024, 08, 24) + }, + new() + { + Uuid = Guid.NewGuid(), + OfficieleTitel = "Inzicht voor Iedereen: Toepassing en Resultaten van de Wet open overheid", + VerkorteTitel = "Inzicht voor Iedereen", + Omschrijving = "", + Creatiedatum = new DateOnly(2024, 05, 02) + } + }.ToDictionary(x=> x.Uuid); + + [HttpGet] + public IActionResult AllPublicaties() => Ok(s_publicaties.Values); + + [HttpGet("{uuid}")] + public IActionResult Single(Guid uuid) => s_publicaties.TryGetValue(uuid, out var publicatie) + ? Ok(publicatie) + : NotFound(); + + [HttpPost] + public IActionResult Post(Publicatie publicatie) + { + publicatie.Uuid = Guid.NewGuid(); + publicatie.Creatiedatum = DateOnly.FromDateTime(DateTime.Now); + s_publicaties[publicatie.Uuid] = publicatie; + return Ok(publicatie); + } + + [HttpPut("{uuid}")] + public IActionResult Put(Guid uuid, Publicatie publicatie) + { + s_publicaties[uuid] = publicatie; + return Ok(publicatie); + } + + [HttpDelete("{uuid}")] + public IActionResult Delete(Guid uuid) + { + s_publicaties.Remove(uuid); + return NoContent(); + } + } +} diff --git a/odpc.client/src/features/publicatie/PublicatieDetails.vue b/odpc.client/src/features/publicatie/PublicatieDetails.vue index e8a7f02..04f418d 100644 --- a/odpc.client/src/features/publicatie/PublicatieDetails.vue +++ b/odpc.client/src/features/publicatie/PublicatieDetails.vue @@ -62,7 +62,7 @@ const publicatie = ref({ }); const { data, isFetching, error, post, put, execute } = useFetchApi( - () => `/api-mock/publicaties${props.id ? "/" + props.id : ""}`, + () => `/api/v1/publicaties${props.id ? "/" + props.id : ""}`, { immediate: false } ).json(); diff --git a/odpc.client/src/features/publicatie/PublicatiesOverview.vue b/odpc.client/src/features/publicatie/PublicatiesOverview.vue index 975428b..def4812 100644 --- a/odpc.client/src/features/publicatie/PublicatiesOverview.vue +++ b/odpc.client/src/features/publicatie/PublicatiesOverview.vue @@ -31,7 +31,7 @@ import SimpleSpinner from "@/components/SimpleSpinner.vue"; import AlertInline from "@/components/AlertInline.vue"; import type { Publicatie } from "./types"; -const { data, isFetching, error } = useFetchApi("/api-mock/publicaties").json(); +const { data, isFetching, error } = useFetchApi("/api/v1/publicaties").json();