using AutoMapper;
using EnvelopeGenerator.Application.Interfaces.Repositories;
using DigitalData.Core.Exceptions;
using MediatR;
namespace EnvelopeGenerator.Application.Histories.Queries.Read;
///
///
///
public class ReadHistoryQueryHandler : IRequestHandler>
{
[Obsolete("Use IRepository")]
private readonly IEnvelopeHistoryRepository _repository;
private readonly IMapper _mapper;
///
///
///
///
///
[Obsolete("Use IRepository")]
public ReadHistoryQueryHandler(IEnvelopeHistoryRepository repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
}
///
///
///
///
///
///
///
public async Task> Handle(ReadHistoryQuery request, CancellationToken cancellationToken)
{
var hists = await _repository.ReadAsync(request.EnvelopeId, status: request.Status is null ? null : request.Status);
if (!hists.Any())
throw new NotFoundException();
return _mapper.Map>(hists);
}
}