From 405215a8bf8e1bc00d2a3320b2bfd09caabd0cb9 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 26 Oct 2026 10:12:02 +0100 Subject: [PATCH] Enhance validation and data reading logic Add validation in CloseWorkflowCommandHandler to reject "Contracts" as a source for closing operations. Modify ReadArray in WorkflowRepository to accept multiple property names, improving flexibility in data retrieval. Refactor database reader logic to extract JSON payloads more robustly, iterating over all fields and results. --- .../CloseWorkflow/CloseWorkflowCommand.cs | 5 ++ .../Repositories/WorkflowRepository.cs | 68 ++++++++++++++----- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflow/CloseWorkflowCommand.cs b/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflow/CloseWorkflowCommand.cs index 47b669a..bc2e451 100644 --- a/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflow/CloseWorkflowCommand.cs +++ b/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflow/CloseWorkflowCommand.cs @@ -87,6 +87,11 @@ public sealed class CloseWorkflowCommandHandler(IWorkflowRepository workflowRepo /// Closing result envelope. public async Task> Handle(CloseWorkflowCommand request, CancellationToken cancellationToken) { + if (string.Equals(request.Source, "Contracts", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidRequestApiException("Quelle 'Contracts' wird fur Closing aktuell nicht unterstutzt"); + } + var decision = mapper.Map(request); var result = await workflowRepository.CloseAsync( diff --git a/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs b/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs index a27873c..2797f2a 100644 --- a/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs +++ b/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs @@ -64,12 +64,12 @@ public sealed class WorkflowRepository(TaskFlowDbContext dbContext, IOptions ReadArray(JsonElement sourceElement, string propertyName) + private static IReadOnlyList ReadArray(JsonElement sourceElement, params string[] propertyNames) { - if (!sourceElement.TryGetProperty(propertyName, out var propertyElement) || propertyElement.ValueKind != JsonValueKind.Array) + foreach (var propertyName in propertyNames) { - return []; + if (!sourceElement.TryGetProperty(propertyName, out var propertyElement) + || propertyElement.ValueKind != JsonValueKind.Array) + { + continue; + } + + return propertyElement.EnumerateArray().Select(item => item.Clone()).ToList(); } - return propertyElement.EnumerateArray().Select(item => item.Clone()).ToList(); + return []; } }