Introduced ReadSingleEnvelopeDocResultQuery and its handler to fetch an envelope's document as a byte array via MediatR. Throws NotFoundException if the document is missing. Includes XML documentation for clarity.
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using MediatR;
|
|
using EnvelopeGenerator.Application.Common.Query;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using DigitalData.Core.Exceptions;
|
|
|
|
namespace EnvelopeGenerator.Application.Envelopes.Queries;
|
|
|
|
/// <summary>
|
|
/// Repräsentiert eine Abfrage für Umschläge.
|
|
/// </summary>
|
|
/// <param name="Envelope"></param>
|
|
public record ReadSingleEnvelopeDocResultQuery(ReadSingleEnvelopeQuery Envelope) : EnvelopeQueryBase, IRequest<byte[]>;
|
|
|
|
/// <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 ?? throw new NotFoundException($"Document for Envelope with ID {request.Envelope.Id} not found");
|
|
}
|
|
} |