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.
83 lines
2.8 KiB
83 lines
2.8 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using LTEMvcApp.Models;
|
|
using LTEMvcApp.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace LTEMvcApp.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 配置管理控制器 - 负责普通客户端配置管理
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ConfigController : ControllerBase
|
|
{
|
|
private readonly WebSocketManagerService _webSocketManager;
|
|
private readonly ILogger<ConfigController> _logger;
|
|
|
|
public ConfigController(WebSocketManagerService webSocketManager, ILogger<ConfigController> logger)
|
|
{
|
|
_webSocketManager = webSocketManager;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客户端配置
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <returns>客户端配置</returns>
|
|
[HttpGet("{clientName}")]
|
|
public ActionResult<ClientConfig?> GetClientConfig(string clientName)
|
|
{
|
|
var config = _webSocketManager.GetClientConfig(clientName);
|
|
if (config == null)
|
|
return NotFound($"客户端 '{clientName}' 不存在");
|
|
|
|
return Ok(config);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有客户端配置
|
|
/// </summary>
|
|
/// <returns>客户端配置列表</returns>
|
|
[HttpGet]
|
|
public ActionResult<List<ClientConfig>> GetAllConfigs()
|
|
{
|
|
var configs = _webSocketManager.GetAllClientConfigs();
|
|
return Ok(configs);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加客户端配置
|
|
/// </summary>
|
|
/// <param name="config">客户端配置</param>
|
|
/// <returns>操作结果</returns>
|
|
[HttpPost]
|
|
public ActionResult AddClientConfig([FromBody] ClientConfig config)
|
|
{
|
|
if (string.IsNullOrEmpty(config.Name))
|
|
return BadRequest("客户端名称不能为空");
|
|
|
|
var success = _webSocketManager.AddClientConfig(config);
|
|
if (success)
|
|
return Ok(new { message = $"客户端 '{config.Name}' 配置已添加" });
|
|
else
|
|
return BadRequest("添加客户端配置失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除客户端配置
|
|
/// </summary>
|
|
/// <param name="clientName">客户端名称</param>
|
|
/// <returns>操作结果</returns>
|
|
[HttpDelete("{clientName}")]
|
|
public ActionResult RemoveClientConfig(string clientName)
|
|
{
|
|
var success = _webSocketManager.RemoveClientConfig(clientName);
|
|
if (success)
|
|
return Ok(new { message = $"客户端 '{clientName}' 配置已移除" });
|
|
else
|
|
return BadRequest($"移除客户端 '{clientName}' 配置失败");
|
|
}
|
|
}
|
|
}
|