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.
This commit is contained in:
2026-04-09 14:46:04 +02:00
parent 1b387238e8
commit 00a9cf06da

View File

@@ -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;
/// <summary>
/// Repräsentiert eine Abfrage für Umschläge.
/// </summary>
public record ReadSingleEnvelopeDocResultQuery() : EnvelopeQueryBase, IRequest<byte[]>
public record ReadSingleEnvelopeDocResultQuery() : IRequest<byte[]>
{
/// <summary>
///
@@ -41,6 +40,8 @@ public class ReadSingleEnvelopeDocResultQueryHandler : IRequestHandler<ReadSingl
public async Task<byte[]> 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");
}
}