添加配置管理功能,包括获取和设置配置值的接口及实现
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 24s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s

This commit is contained in:
孙诚
2026-01-05 15:21:13 +08:00
parent 5a824dac91
commit d44cceb6e4
8 changed files with 306 additions and 22 deletions

View File

@@ -0,0 +1,41 @@
namespace WebApi.Controllers;
[ApiController]
[Route("api/[controller]/[action]")]
public class ConfigController(
IConfigService configService
) : ControllerBase
{
/// <summary>
/// 获取配置值
/// </summary>
public async Task<BaseResponse<string>> GetConfig(string key)
{
try
{
var config = await configService.GetConfigByKeyAsync<string>(key);
var value = config ?? string.Empty;
return value.Ok("配置获取成功");
}
catch (Exception ex)
{
return $"获取{key}配置失败: {ex.Message}".Fail<string>();
}
}
/// <summary>
/// 设置配置值
/// </summary>
public async Task<BaseResponse> SetConfig(string key, string value)
{
try
{
await configService.SetConfigByKeyAsync(key, value);
return "配置设置成功".Ok();
}
catch (Exception ex)
{
return $"设置{key}配置失败: {ex.Message}".Fail();
}
}
}