You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.1 KiB
87 lines
3.1 KiB
6 days ago
|
using System.Threading.Tasks;
|
||
|
using CoreAgent.Application.Commands.NetworkConfig;
|
||
|
using CoreAgent.Application.Queries.NetworkConfig;
|
||
|
using CoreAgent.Domain.Entities;
|
||
|
using MediatR;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
|
||
|
namespace CoreAgent.API.Controllers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 网络配置控制器
|
||
|
/// </summary>
|
||
|
[ApiVersion("1.0")]
|
||
|
public class NetworkConfigController : BaseApiController
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 构造函数
|
||
|
/// </summary>
|
||
|
/// <param name="mediator">中介者</param>
|
||
|
/// <param name="logger">日志记录器</param>
|
||
|
public NetworkConfigController(IMediator mediator, ILogger<NetworkConfigController> logger)
|
||
|
: base(mediator, logger)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取所有网络配置
|
||
|
/// </summary>
|
||
|
/// <returns>网络配置列表</returns>
|
||
|
[HttpGet]
|
||
|
[ProducesResponseType(typeof(List<NetworkConfiguration>), 200)]
|
||
|
public async Task<IActionResult> GetAll()
|
||
|
{
|
||
|
return await HandleRequest<GetAllNetworkConfigurationsQuery, List<NetworkConfiguration>>(
|
||
|
new GetAllNetworkConfigurationsQuery());
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据配置键获取网络配置
|
||
|
/// </summary>
|
||
|
/// <param name="configKey">配置键值</param>
|
||
|
/// <returns>网络配置</returns>
|
||
|
[HttpGet("{configKey}")]
|
||
|
[ProducesResponseType(typeof(NetworkConfiguration), 200)]
|
||
|
[ProducesResponseType(404)]
|
||
|
public async Task<IActionResult> GetByKey(string configKey)
|
||
|
{
|
||
|
return await HandleRequest<GetNetworkConfigurationByKeyQuery, NetworkConfiguration>(
|
||
|
new GetNetworkConfigurationByKeyQuery { ConfigKey = configKey });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 创建网络配置
|
||
|
/// </summary>
|
||
|
/// <param name="command">创建网络配置命令</param>
|
||
|
/// <returns>创建的网络配置</returns>
|
||
|
[HttpPost]
|
||
|
[ProducesResponseType(typeof(NetworkConfiguration), 201)]
|
||
|
[ProducesResponseType(400)]
|
||
|
public async Task<IActionResult> Create([FromBody] CreateNetworkConfigurationCommand command)
|
||
|
{
|
||
|
var result = await HandleRequest<CreateNetworkConfigurationCommand, NetworkConfiguration>(command);
|
||
|
if (result is OkObjectResult okResult)
|
||
|
{
|
||
|
return CreatedAtAction(nameof(GetByKey),
|
||
|
new { configKey = command.ConfigKey },
|
||
|
okResult.Value);
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除网络配置
|
||
|
/// </summary>
|
||
|
/// <param name="configKey">配置键值</param>
|
||
|
/// <returns>操作结果</returns>
|
||
|
[HttpDelete("{configKey}")]
|
||
|
[ProducesResponseType(204)]
|
||
|
[ProducesResponseType(404)]
|
||
|
public async Task<IActionResult> Delete(string configKey)
|
||
|
{
|
||
|
var command = new DeleteNetworkConfigurationCommand { ConfigKey = configKey };
|
||
|
return await HandleRequest<DeleteNetworkConfigurationCommand, Unit>(command);
|
||
|
}
|
||
|
}
|
||
|
}
|