ActionConfigurationController.cs
3.15 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Microsoft.AspNetCore.Mvc;
using Rcs.Application.Common;
using MassTransit.Mediator;
using Rcs.Application.DTOs;
using Rcs.Application.MessageBus.Commands;
using Rcs.Infrastructure.MessageBus.Handlers.Commands;
namespace Rcs.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ActionConfigurationController : ControllerBase
{
private readonly IMediator _mediator;
public ActionConfigurationController(IMediator mediator)
{
_mediator = mediator;
}
/// <summary>
/// 获取去重的动作类别列表
/// @author zzy
/// </summary>
[HttpGet("categories")]
public async Task<IActionResult> GetCategories([FromQuery] GetActionCategoriesQuery query, CancellationToken cancellationToken = default)
{
var client = _mediator.CreateRequestClient<GetActionCategoriesQuery>();
var response = await client.GetResponse<ApiResponse<List<ActionCategoryDto>>>(query, cancellationToken);
return Ok(response.Message);
}
[HttpGet]
public async Task<IActionResult> GetList([FromQuery] GetActionConfigurationsQuery query, CancellationToken cancellationToken = default)
{
var client = _mediator.CreateRequestClient<GetActionConfigurationsQuery>();
var response = await client.GetResponse<PagedResponse<ActionConfigurationListItemDto>>(query, cancellationToken);
return Ok(response.Message);
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(string id, CancellationToken cancellationToken = default)
{
if (!Guid.TryParse(id, out Guid actionConfigId))
{
return BadRequest(ApiResponse.Failed("无效的ID格式"));
}
var client = _mediator.CreateRequestClient<GetActionConfigurationQuery>();
var response = await client.GetResponse<ApiResponse<ActionConfigurationDto>>(new GetActionConfigurationQuery
{
ActionConfigId = actionConfigId
}, cancellationToken);
return Ok(response.Message);
}
[HttpPost]
public async Task<IActionResult> CreateOrUpdate([FromBody] CreateOrUpdateActionConfigurationCommand command)
{
var client = _mediator.CreateRequestClient<CreateOrUpdateActionConfigurationCommand>();
var response = await client.GetResponse<ApiResponse>(command);
return Ok(response.Message);
}
[HttpPost("{id}")]
public async Task<IActionResult> Delete(string id, CancellationToken cancellationToken = default)
{
if (!Guid.TryParse(id, out Guid actionConfigId))
{
return BadRequest(ApiResponse.Failed("无效的ID格式"));
}
var client = _mediator.CreateRequestClient<DeleteActionConfigurationCommand>();
var response = await client.GetResponse<ApiResponse>(new DeleteActionConfigurationCommand
{
ActionConfigId = actionConfigId
}, cancellationToken);
return Ok(response.Message);
}
}
}