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:
@@ -1,5 +1,4 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using EnvelopeGenerator.Application.Common.Query;
|
|
||||||
using EnvelopeGenerator.Application.Common.Dto;
|
using EnvelopeGenerator.Application.Common.Dto;
|
||||||
using DigitalData.Core.Exceptions;
|
using DigitalData.Core.Exceptions;
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ namespace EnvelopeGenerator.Application.Envelopes.Queries;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Repräsentiert eine Abfrage für Umschläge.
|
/// Repräsentiert eine Abfrage für Umschläge.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record ReadSingleEnvelopeDocResultQuery() : EnvelopeQueryBase, IRequest<byte[]>
|
public record ReadSingleEnvelopeDocResultQuery() : IRequest<byte[]>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -41,6 +40,8 @@ public class ReadSingleEnvelopeDocResultQueryHandler : IRequestHandler<ReadSingl
|
|||||||
public async Task<byte[]> Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken)
|
public async Task<byte[]> Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var result = await _mediator.Send(request.Envelope, 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user