using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Api;
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Api.Output;
using ATS.NonCustodial.Shared.Common.Attributes;
using ATS.NonCustodial.Shared.Common.UnifiedResults;
using ATS.NonCustodial.Shared.Extensions;
namespace ATS.NonCustodial.AdminUi.Helpers.Logs
{
///
/// Api帮助类
///
/// Author:mxg
/// CreatedTimed:2022-05-18 09:46 AM
[SingleInstance]
public class ApiHelper
{
#region Identity
private List _apis;
private static readonly object LockObject = new();
private readonly IApiService _apiService;
public ApiHelper(IApiService apiService)
{
_apiService = apiService;
}
#endregion Identity
///
/// 主要是在Action 操作的时候添加操作日志时候用
///
///
public List GetApis()
{
if (_apis != null && _apis.Any()) return _apis;
lock (LockObject)
{
if (_apis != null && _apis.Any()) return _apis;
_apis = new List();
var apis = ((ResultOutput>)_apiService.GetListAsync("").Result)
.Data
.Select(a => new
{
a.Id,
a.ParentId,
a.Label,
a.Path
});
foreach (var api in apis)
{
var parentLabel = apis.FirstOrDefault(a => a.Id == api.ParentId)?.Label;
_apis.Add(new ApiHelperDto
{
Label = parentLabel.NotNull() ? $"{parentLabel} / {api.Label}" : api.Label,
Path = api.Path?.ToLower().Trim('/')
});
}
return _apis;
}
}
}
///
///
///
public class ApiHelperDto
{
///
/// 接口名称
///
public string Label { get; set; }
///
/// 接口地址
///
public string Path { get; set; }
}
}