using AutoMapper; using EnvelopeGenerator.Application.Contracts.Repositories; using EnvelopeGenerator.Application.Exceptions; using MediatR; namespace EnvelopeGenerator.Application.Histories.Queries.Read; /// /// /// public class ReadHistoryQueryHandler : IRequestHandler> { private readonly IEnvelopeHistoryRepository _repository; private readonly IMapper _mapper; /// /// /// /// /// 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 : (int) request.Status); if (!hists.Any()) throw new NotFoundException(); return _mapper.Map>(hists); } }