47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Exceptions;
|
|
using EnvelopeGenerator.Application.Dto.EnvelopeHistory;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.Histories.Queries;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<EnvelopeHistoryDto>>
|
|
{
|
|
private readonly IRepository<EnvelopeHistory> _repo;
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repo"></param>
|
|
/// <param name="mapper"></param>
|
|
public ReadHistoryQueryHandler(IRepository<EnvelopeHistory> repo, IMapper mapper)
|
|
{
|
|
_repo = repo;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotFoundException"></exception>
|
|
public async Task<IEnumerable<EnvelopeHistoryDto>> Handle(ReadHistoryQuery request, CancellationToken cancel = default)
|
|
{
|
|
var query = _repo.ReadOnly().Where(h => h.EnvelopeId == request.EnvelopeId);
|
|
if (request.Status is not null)
|
|
query = query.Where(h => h.Status == request.Status);
|
|
|
|
var hists = await query.ToListAsync(cancel);
|
|
return _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(hists);
|
|
}
|
|
} |