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.
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using MediatR;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using DigitalData.Core.Exceptions;
|
|
|
|
namespace EnvelopeGenerator.Application.Envelopes.Queries;
|
|
|
|
/// <summary>
|
|
/// Repräsentiert eine Abfrage für Umschläge.
|
|
/// </summary>
|
|
public record ReadSingleEnvelopeDocResultQuery() : IRequest<byte[]>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public ReadSingleEnvelopeQuery Envelope { get; set; } = null!;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verarbeitet <see cref="ReadEnvelopeQuery"/> und liefert passende <see cref="EnvelopeDto"/>-Ergebnisse.
|
|
/// </summary>
|
|
public class ReadSingleEnvelopeDocResultQueryHandler : IRequestHandler<ReadSingleEnvelopeDocResultQuery, byte[]>
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="mediator"></param>
|
|
public ReadSingleEnvelopeDocResultQueryHandler(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<byte[]> Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var result = await _mediator.Send(request.Envelope, cancellationToken);
|
|
return result.DocResult is byte[] docResult && docResult.Length > 0
|
|
? docResult
|
|
: throw new NotFoundException($"Document for Envelope with ID {request.Envelope.Id} not found");
|
|
}
|
|
} |