using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.SysDatabaseLink;
using OpenAuth.App.SysDatabaseLink.Response;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Domain;
namespace OpenAuth.WebApi.Controllers
{
///
/// 数据库连接管理
///
[Route("api/[controller]/[action]")]
[ApiController]
public class SysDatabaseLinkController:ControllerBase
{
private readonly SysDatabaseLinkApp _app;
public SysDatabaseLinkController(SysDatabaseLinkApp app)
{
_app = app;
}
///
/// 获取数据库树
///
///
[HttpGet]
public async Task>> LoadDataBaseLinkTree()
{
return await _app.LoadDataBaseLinkTree();
}
///
/// 分页获取列表数据
///
/// 筛选条件
/// 当前页
/// 每页条数
///
[HttpGet]
public async Task>>> LoadDataBaseInfo(string keyword, int page = 1, int limit = 15)
{
return await _app.LoadDataBaseInfo(keyword,page,limit);
}
///
/// 根据主键获取实体数据(编辑时使用)
///
/// 主键
///
[HttpGet]
public async Task> GetDataBaseForm(string id)
{
return await _app.GetDataBaseForm(id);
}
///
///新增数据库连接
///
/// 数据库实体
///
[HttpPost]
public async Task> AddBaseLinkForm(Repository.Domain.SysDatabaseLink baseLink)
{
var result = new Response();
try
{
result = await _app.SaveBaseLinkEntity(String.Empty, baseLink);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///
///更新数据库连接
///
/// 主键值
/// 数据库实体
///
[HttpPost]
public async Task> UpdateBaseLink(string keyValue, Repository.Domain.SysDatabaseLink baseLink)
{
var result = new Response();
try
{
result = await _app.SaveBaseLinkEntity(keyValue, baseLink);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///
/// 删除数据库连接
///
/// 主键
///
[HttpPost]
public async Task> DeleteBaseLink(string id)
{
var result = new Response();
try
{
result = await _app.DeleteBaseLink(id);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
///
/// 测试连接串是否正确
///
/// 连接串
/// 数据库类型
/// 主键
///
[HttpGet]
public async Task> TestConnection(string connection, string dbType, string id)
{
var result = new Response();
try
{
result = await _app.TestDataBaseLink(connection, dbType, id);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
}
}