46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using AutoMapper;
|
|
using EnvelopeGenerator.Application.Interfaces.Repositories;
|
|
using EnvelopeGenerator.Application.Exceptions;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Histories.Queries.Read;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<ReadHistoryResponse>>
|
|
{
|
|
[Obsolete("Use IRepository")]
|
|
private readonly IEnvelopeHistoryRepository _repository;
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
/// <param name="mapper"></param>
|
|
[Obsolete("Use IRepository")]
|
|
public ReadHistoryQueryHandler(IEnvelopeHistoryRepository repository, IMapper mapper)
|
|
{
|
|
_repository = repository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotFoundException"></exception>
|
|
public async Task<IEnumerable<ReadHistoryResponse>> 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<IEnumerable<ReadHistoryResponse>>(hists);
|
|
}
|
|
} |