From 00a9cf06dae450a49d455b311d425c28b0440d52 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 9 Apr 2026 14:46:04 +0200 Subject: [PATCH] Refactor envelope doc query and improve result validation Refactored ReadSingleEnvelopeDocResultQuery to remove inheritance from EnvelopeQueryBase and introduce an Envelope property. Enhanced the handler to ensure DocResult is a non-empty byte array before returning, throwing NotFoundException otherwise. --- .../Envelopes/Queries/ReadSingleEnvelopeDocResultQuery.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/EnvelopeGenerator.Application/Envelopes/Queries/ReadSingleEnvelopeDocResultQuery.cs b/EnvelopeGenerator.Application/Envelopes/Queries/ReadSingleEnvelopeDocResultQuery.cs index f2bb0f0e..fd8451d7 100644 --- a/EnvelopeGenerator.Application/Envelopes/Queries/ReadSingleEnvelopeDocResultQuery.cs +++ b/EnvelopeGenerator.Application/Envelopes/Queries/ReadSingleEnvelopeDocResultQuery.cs @@ -1,5 +1,4 @@ using MediatR; -using EnvelopeGenerator.Application.Common.Query; using EnvelopeGenerator.Application.Common.Dto; using DigitalData.Core.Exceptions; @@ -8,7 +7,7 @@ namespace EnvelopeGenerator.Application.Envelopes.Queries; /// /// Repräsentiert eine Abfrage für Umschläge. /// -public record ReadSingleEnvelopeDocResultQuery() : EnvelopeQueryBase, IRequest +public record ReadSingleEnvelopeDocResultQuery() : IRequest { /// /// @@ -41,6 +40,8 @@ public class ReadSingleEnvelopeDocResultQueryHandler : IRequestHandler Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken) { var result = await _mediator.Send(request.Envelope, cancellationToken); - return result.DocResult ?? throw new NotFoundException($"Document for Envelope with ID {request.Envelope.Id} not found"); + return result.DocResult is byte[] docResult && docResult.Length > 0 + ? docResult + : throw new NotFoundException($"Document for Envelope with ID {request.Envelope.Id} not found"); } } \ No newline at end of file