From 7c85e338fa349da2a6e8e431f6a04cb5c45336bb Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Wed, 29 Oct 2025 07:57:13 +0100 Subject: [PATCH] Json Parsing --- Watcher/Controllers/MonitoringController.cs | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Watcher/Controllers/MonitoringController.cs b/Watcher/Controllers/MonitoringController.cs index e5963a7..0f4e2a3 100644 --- a/Watcher/Controllers/MonitoringController.cs +++ b/Watcher/Controllers/MonitoringController.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -236,8 +237,26 @@ public class MonitoringController : Controller return BadRequest(new { error = "Invalid Payload", details = errors }); } + // Json zu was brauchbarem machen + string containersJson = await dto.Containers.ReadAsStringAsync(); + List newContainers = JsonSerializer.Deserialize>(containersJson)?? new List();; + + foreach (Container c in newContainers) + { + c.ServerId = dto.Server_id; + // Debug Logs + // TODO entfernen wenn fertig getestet + Console.WriteLine("---------"); + Console.WriteLine("ServerId: " + c.ServerId); + Console.WriteLine("ContainerId: " + c.ContainerId); + Console.WriteLine("Name: " + c.Name); + Console.WriteLine("Image: " + c.Image); + Console.WriteLine("---------"); + + } + // Container Objekte erstellen - List newContainers = ParseServiceDiscoveryInput(dto.Server_id, dto.Containers); + //List newContainers = ParseServiceDiscoveryInput(dto.Server_id, containers); // Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind List existingContainers = _context.Containers @@ -391,7 +410,7 @@ public class MonitoringController : Controller return metric_input; } - private List ParseServiceDiscoveryInput(int server_id, JsonContent containers) + private List ParseServiceDiscoveryInput(int server_id, List containers) { List containerList = new List();