using System;
using System.Threading.Tasks;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Response;
namespace OpenAuth.WebApi.Controllers
{
///
/// 动态实体API控制器
/// 用于处理任意实体的CRUD操作
///
[Route("api/dynamic/[action]")]
[ApiController]
[ApiExplorerSettings(GroupName = "动态API_DynamicEntity")]
public class DynamicApiController : ControllerBase
{
private readonly DynamicApiApp _app;
public DynamicApiController(DynamicApiApp app)
{
_app = app;
}
///
/// 获取实体列表
///
/// 实体名称,例如:ExternalDataSource
/// 页码
/// 每页记录数
/// 搜索关键字
///
[HttpGet]
public async Task GetList(string entityName, int page = 1, int limit = 10, string key = "")
{
TableData result = new TableData();
try
{
// 获取实体类型
result = await _app.GetList(entityName, page, limit, key);
}
catch (Exception ex)
{
result.code = 500;
result.msg = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///
/// 获取实体详情
///
/// 实体名称,例如:ExternalDataSource
/// 实体ID
///
[HttpGet]
public Response