GetActionConfigurationQueryHandler.cs
1.59 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
using MassTransit;
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 GetActionConfigurationQueryHandler : IConsumer<GetActionConfigurationQuery>
{
private readonly ILogger<GetActionConfigurationQueryHandler> _logger;
private readonly IActionConfigurationRepository _repository;
private readonly IMapper _mapper;
public GetActionConfigurationQueryHandler(
ILogger<GetActionConfigurationQueryHandler> logger,
IActionConfigurationRepository repository,
IMapper mapper)
{
_logger = logger;
_repository = repository;
_mapper = mapper;
}
public async Task Consume(ConsumeContext<GetActionConfigurationQuery> context)
{
var query = context.Message;
try
{
var data = await _repository.GetWithParametersAsync(query.ActionConfigId, context.CancellationToken);
if (data == null)
{
await context.RespondAsync(ApiResponse<ActionConfigurationDto>.Failed("未找到该动作配置"));
return;
}
var dto = _mapper.Map<ActionConfigurationDto>(data);
await context.RespondAsync(ApiResponse<ActionConfigurationDto>.Successful(dto));
}
catch (Exception ex)
{
await context.RespondAsync(ApiResponse<ActionConfigurationDto>.Failed(ex.Message));
}
}
}