GetActionConfigurationsQueryHandler.cs
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using MassTransit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Rcs.Application.Common;
using Rcs.Application.DTOs;
using Rcs.Application.MessageBus.Commands;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using AutoMapper;
namespace Rcs.Infrastructure.MessageBus.Handlers.Commands;
public class GetActionConfigurationsQueryHandler : IConsumer<GetActionConfigurationsQuery>
{
private readonly ILogger<GetActionConfigurationsQueryHandler> _logger;
private readonly IActionConfigurationRepository _repository;
private readonly IMapper _mapper;
public GetActionConfigurationsQueryHandler(
ILogger<GetActionConfigurationsQueryHandler> logger,
IActionConfigurationRepository repository,
IMapper mapper)
{
_logger = logger;
_repository = repository;
_mapper = mapper;
}
public async Task Consume(ConsumeContext<GetActionConfigurationsQuery> context)
{
var query = context.Message;
var queryable = _repository.GetQueryable();
if (!string.IsNullOrWhiteSpace(query.FilterModel))
{
queryable = FilterHelper.ApplyFilters(queryable, query.FilterModel);
}
var totalCount = await queryable.CountAsync(context.CancellationToken);
var data = await queryable
.OrderBy(x => x.SortOrder)
.ThenBy(x => x.CreatedAt)
.Skip((query.PageNumber - 1) * query.PageSize)
.Take(query.PageSize)
.ToListAsync(context.CancellationToken);
var dtos = _mapper.Map<List<ActionConfigurationListItemDto>>(data);
await context.RespondAsync(PagedResponse<ActionConfigurationListItemDto>.Successful(dtos, query.PageNumber, query.PageSize, totalCount));
}
}