Updated IEnvelopeHistoryRepository and IEnvelopeHistoryService interfaces to replace int? status with Constants.EnvelopeStatus? status in CountAsync and ReadAsync methods. Adjusted ReadHistoryQueryHandler and EnvelopeHistoryService methods to accommodate the new type. Modified EnvelopeHistoryRepository to accept Constants.EnvelopeStatus? in relevant methods and marked it as obsolete, suggesting a future refactor.
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using AutoMapper;
|
|
using EnvelopeGenerator.Application.Contracts.Repositories;
|
|
using EnvelopeGenerator.Application.Exceptions;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Histories.Queries.Read;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<ReadHistoryResponse>>
|
|
{
|
|
private readonly IEnvelopeHistoryRepository _repository;
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
/// <param name="mapper"></param>
|
|
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);
|
|
}
|
|
}
|