|
|
|
using System.Threading.Tasks;
|
|
|
|
using CoreAgent.Application.Commands.NetworkConfig;
|
|
|
|
using CoreAgent.Domain.Entities;
|
|
|
|
using CoreAgent.Domain.Models.Common;
|
|
|
|
using MediatR;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
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(ApiActionResult<List<NetworkConfiguration>>), 200)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<List<NetworkConfiguration>>), 500)]
|
|
|
|
public async Task<IActionResult> GetAll()
|
|
|
|
{
|
|
|
|
return await HandleRequest<GetAllNetworkConfigurationsQuery, ApiActionResult<List<NetworkConfiguration>>>(
|
|
|
|
new GetAllNetworkConfigurationsQuery());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据配置键获取网络配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configKey">配置键值</param>
|
|
|
|
/// <returns>网络配置</returns>
|
|
|
|
[HttpGet("{configKey}")]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 200)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 404)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 500)]
|
|
|
|
public async Task<IActionResult> GetByKey(string configKey)
|
|
|
|
{
|
|
|
|
return await HandleRequest<GetNetworkConfigurationByKeyQuery, ApiActionResult<NetworkConfiguration>>(
|
|
|
|
new GetNetworkConfigurationByKeyQuery { ConfigKey = configKey });
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建网络配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="command">创建网络配置命令</param>
|
|
|
|
/// <returns>创建的网络配置</returns>
|
|
|
|
[HttpPost]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 200)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 400)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<NetworkConfiguration>), 500)]
|
|
|
|
public async Task<IActionResult> Create([FromBody] CreateNetworkConfigurationCommand command)
|
|
|
|
{
|
|
|
|
return await HandleRequest<CreateNetworkConfigurationCommand, ApiActionResult<NetworkConfiguration>>(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除网络配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configKey">配置键值</param>
|
|
|
|
/// <returns>操作结果</returns>
|
|
|
|
[HttpDelete("{configKey}")]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<bool>), 200)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<bool>), 400)]
|
|
|
|
[ProducesResponseType(typeof(ApiActionResult<bool>), 500)]
|
|
|
|
public async Task<IActionResult> Delete(string configKey)
|
|
|
|
{
|
|
|
|
var command = new DeleteNetworkConfigurationCommand { ConfigKey = configKey };
|
|
|
|
return await HandleRequest<DeleteNetworkConfigurationCommand, ApiActionResult<bool>>(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|