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 { /// /// 网络配置控制器 /// [ApiVersion("1.0")] public class NetworkConfigController : BaseApiController { /// /// 构造函数 /// /// 中介者 /// 日志记录器 public NetworkConfigController(IMediator mediator, ILogger logger) : base(mediator, logger) { } /// /// 获取所有网络配置 /// /// 网络配置列表 [HttpGet] [ProducesResponseType(typeof(ApiActionResult>), 200)] [ProducesResponseType(typeof(ApiActionResult>), 500)] public async Task GetAll() { return await HandleRequest>>( new GetAllNetworkConfigurationsQuery()); } /// /// 根据配置键获取网络配置 /// /// 配置键值 /// 网络配置 [HttpGet("{configKey}")] [ProducesResponseType(typeof(ApiActionResult), 200)] [ProducesResponseType(typeof(ApiActionResult), 404)] [ProducesResponseType(typeof(ApiActionResult), 500)] public async Task GetByKey(string configKey) { return await HandleRequest>( new GetNetworkConfigurationByKeyQuery { ConfigKey = configKey }); } /// /// 创建网络配置 /// /// 创建网络配置命令 /// 创建的网络配置 [HttpPost] [ProducesResponseType(typeof(ApiActionResult), 200)] [ProducesResponseType(typeof(ApiActionResult), 400)] [ProducesResponseType(typeof(ApiActionResult), 500)] public async Task Create([FromBody] CreateNetworkConfigurationCommand command) { return await HandleRequest>(command); } /// /// 删除网络配置 /// /// 配置键值 /// 操作结果 [HttpDelete("{configKey}")] [ProducesResponseType(typeof(ApiActionResult), 200)] [ProducesResponseType(typeof(ApiActionResult), 400)] [ProducesResponseType(typeof(ApiActionResult), 500)] public async Task Delete(string configKey) { var command = new DeleteNetworkConfigurationCommand { ConfigKey = configKey }; return await HandleRequest>(command); } } }