diff --git a/Directory.Packages.props b/Directory.Packages.props index f6010c4..53f66bc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,10 +2,10 @@ true true - 8.1.21 + 8.1.22 - + @@ -29,22 +29,22 @@ - - + + - + - - - - + + + + - + - - - + + + @@ -52,14 +52,14 @@ - + - - - - - + + + + + @@ -72,7 +72,7 @@ - + @@ -102,9 +102,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Source/Starfish.Client/Clients/HttpConfigurationClient.cs b/Source/Starfish.Client/Clients/HttpConfigurationClient.cs index 22054c4..bdf0f49 100644 --- a/Source/Starfish.Client/Clients/HttpConfigurationClient.cs +++ b/Source/Starfish.Client/Clients/HttpConfigurationClient.cs @@ -4,16 +4,14 @@ internal class HttpConfigurationClient : IConfigurationClient { private readonly HttpClient _httpClient = new(); - private readonly string _app; + private readonly string _id; private readonly string _secret; - private readonly string _env; - public HttpConfigurationClient(Uri host, string app, string secret, string env) + public HttpConfigurationClient(Uri host, string id, string secret) { _httpClient.BaseAddress = host; - _app = app; + _id = id; _secret = secret; - _env = env; // _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Team, team); // _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.App, app); @@ -28,7 +26,7 @@ public async Task GetConfigurationAsync(Action dataAction, Cancella try { attempts++; - using var request = new HttpRequestMessage(HttpMethod.Get, $"es?app={_app}&secret={_secret}&env={_env}"); + using var request = new HttpRequestMessage(HttpMethod.Get, $"es?id={_id}&secret={_secret}"); var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); diff --git a/Source/Starfish.Client/Clients/SocketConfigurationClient.cs b/Source/Starfish.Client/Clients/SocketConfigurationClient.cs index 93b827f..6f43c34 100644 --- a/Source/Starfish.Client/Clients/SocketConfigurationClient.cs +++ b/Source/Starfish.Client/Clients/SocketConfigurationClient.cs @@ -7,9 +7,9 @@ internal class SocketConfigurationClient : IConfigurationClient private readonly ClientWebSocket _client = new(); private readonly Uri _uri; - public SocketConfigurationClient(Uri host, string app, string secret, string env) + public SocketConfigurationClient(Uri host, string id, string secret) { - _uri = new Uri($"{host.AbsoluteUri}ws?app={app}&secret={secret}&env={env}"); + _uri = new Uri($"{host.AbsoluteUri}ws?app={id}&secret={secret}"); // _client.Options.SetRequestHeader(Constants.RequestHeaders.Team, team); // _client.Options.SetRequestHeader(Constants.RequestHeaders.App, app); // _client.Options.SetRequestHeader(Constants.RequestHeaders.Secret, secret); diff --git a/Source/Starfish.Client/ConfigurationClientOptions.cs b/Source/Starfish.Client/ConfigurationClientOptions.cs index 8591507..6319cf6 100644 --- a/Source/Starfish.Client/ConfigurationClientOptions.cs +++ b/Source/Starfish.Client/ConfigurationClientOptions.cs @@ -10,12 +10,7 @@ public class ConfigurationClientOptions /// /// 应用Id /// - public string App { get; set; } - - /// - /// 应用环境 - /// - public string Env { get; set; } + public string Id { get; set; } /// /// 密钥 @@ -67,9 +62,9 @@ public static ConfigurationClientOptions Load(IConfiguration configuration) throw new InvalidOperationException(Resources.IDS_ERROR_STARFISH_SECTION_NOT_FOUND); } - var app = section[nameof(App)]; + var id = section[nameof(Id)]; - if (string.IsNullOrWhiteSpace(app)) + if (string.IsNullOrWhiteSpace(id)) { throw new InvalidOperationException(Resources.IDS_ERROR_APP_SECTION_NOT_FOUND); } @@ -83,8 +78,7 @@ public static ConfigurationClientOptions Load(IConfiguration configuration) var options = new ConfigurationClientOptions { Host = host, - App = app, - Env = section[nameof(Env)] ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"), + Id = id, Secret = section[nameof(Secret)], CacheDirectory = section[nameof(CacheDirectory)] ?? AppDomain.CurrentDomain.BaseDirectory }; diff --git a/Source/Starfish.Client/StarfishConfigurationProvider.cs b/Source/Starfish.Client/StarfishConfigurationProvider.cs index 5a4a1e2..14dd668 100644 --- a/Source/Starfish.Client/StarfishConfigurationProvider.cs +++ b/Source/Starfish.Client/StarfishConfigurationProvider.cs @@ -21,7 +21,7 @@ internal class StarfishConfigurationProvider : ConfigurationProvider, IDisposabl public StarfishConfigurationProvider(ConfigurationClientOptions options) { _options = options; - _cacheFile = Path.Combine(_options.CacheDirectory, $"{_options.App}.starfish.{_options.Env}.cache"); + _cacheFile = Path.Combine(_options.CacheDirectory, $"{_options.Id}.starfish.cache"); HostChanged += OnHostChanged; ConnectionLost += (_, _) => { @@ -58,8 +58,8 @@ private async void OnHostChanged(object sender, HostChangedEventArgs args) var uri = new Uri(args.Host); IConfigurationClient client = uri.Scheme switch { - "http" or "https" => new HttpConfigurationClient(uri, _options.App, _options.Secret, _options.Env), - "ws" or "wss" => new SocketConfigurationClient(uri, _options.App, _options.Secret, _options.Env), + "http" or "https" => new HttpConfigurationClient(uri, _options.Id, _options.Secret), + "ws" or "wss" => new SocketConfigurationClient(uri, _options.Id, _options.Secret), _ => throw new NotSupportedException(string.Format(Resources.IDS_ERROR_SCHEMA_NOT_SUPPORTED, uri.Scheme)), }; try diff --git a/Source/Starfish.Common/PermissionState.cs b/Source/Starfish.Common/PermissionState.cs new file mode 100644 index 0000000..52d969e --- /dev/null +++ b/Source/Starfish.Common/PermissionState.cs @@ -0,0 +1,8 @@ +namespace Nerosoft.Starfish.Common; + +public enum PermissionState +{ + None = 0, + Read = 1, + Edit = 2 +} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/ApplicationServiceModule.cs b/Source/Starfish.Service/Application/ApplicationServiceModule.cs index cabe786..26e53bc 100644 --- a/Source/Starfish.Service/Application/ApplicationServiceModule.cs +++ b/Source/Starfish.Service/Application/ApplicationServiceModule.cs @@ -32,7 +32,6 @@ public override void AheadConfigureServices(ServiceConfigurationContext context) { options.AddProfile(); options.AddProfile(); - options.AddProfile(); options.AddProfile(); }); } diff --git a/Source/Starfish.Service/Application/Commands/Configs/AppInfoCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/AppInfoCreateCommand.cs deleted file mode 100644 index ca664de..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/AppInfoCreateCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Nerosoft.Euonia.Domain; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.Application; - -/// -/// 创建应用信息命令 -/// -public class AppInfoCreateCommand : Command -{ - /// - /// 构造函数 - /// - /// - public AppInfoCreateCommand(AppInfoCreateDto data) - : base(data) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/AppInfoDeleteCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/AppInfoDeleteCommand.cs deleted file mode 100644 index 22523fa..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/AppInfoDeleteCommand.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Application; - -/// -/// 删除应用信息命令 -/// -public class AppInfoDeleteCommand : Command -{ - /// - /// 构造函数 - /// - /// - public AppInfoDeleteCommand(string id) - : base(id) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/AppInfoUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/AppInfoUpdateCommand.cs deleted file mode 100644 index fb83019..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/AppInfoUpdateCommand.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Nerosoft.Euonia.Domain; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.Application; - -/// -/// 更新应用信息命令 -/// -public class AppInfoUpdateCommand : Command -{ - /// - /// 构造函数 - /// - /// - /// - public AppInfoUpdateCommand(string id, AppInfoUpdateDto model) - : base(id, model) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ChangeAppStatusCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ChangeAppStatusCommand.cs deleted file mode 100644 index ded56f7..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/ChangeAppStatusCommand.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Nerosoft.Euonia.Domain; -using Nerosoft.Starfish.Domain; - -namespace Nerosoft.Starfish.Application; - -/// -/// 修改应用信息状态命令 -/// -public class ChangeAppStatusCommand : Command -{ - /// - /// 构造函数 - /// - /// - /// - public ChangeAppStatusCommand(string id, AppStatus status) - { - Id = id; - Status = status; - } - - public string Id { get; set; } - - public AppStatus Status { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationAbstractCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationAbstractCommand.cs deleted file mode 100644 index 1b39777..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationAbstractCommand.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Application; - -public abstract class ConfigurationAbstractCommand : Command -{ - protected ConfigurationAbstractCommand(string appId, string environment) - { - AppId = appId; - Environment = environment; - } - - /// - /// 应用Id - /// - public string AppId { get; set; } - - /// - /// 应用环境 - /// - public string Environment { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationArchiveCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationArchiveCreateCommand.cs deleted file mode 100644 index 5ffdc85..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationArchiveCreateCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Application; - -/// -/// 创建配置归档命令 -/// -public class ConfigurationArchiveCreateCommand : Command -{ - /// - /// 应用Id - /// - public string AppId { get; set; } - - /// - /// 应用环境 - /// - public string Environment { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationCreateCommand.cs index 2e0d582..c1ef14e 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationCreateCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationCreateCommand.cs @@ -1,19 +1,19 @@ -namespace Nerosoft.Starfish.Application; +using Nerosoft.Euonia.Domain; -public class ConfigurationCreateCommand : ConfigurationAbstractCommand +namespace Nerosoft.Starfish.Application; + +public class ConfigurationCreateCommand : Command { - public ConfigurationCreateCommand(string appId, string environment) - : base(appId, environment) + public ConfigurationCreateCommand(string teamId) { + TeamId = teamId; } - - /// - /// 描述 - /// + + public string TeamId { get; set; } + + public string Name { get; set; } + public string Description { get; set; } - /// - /// 配置项内容 - /// - public IDictionary Data { get; set; } + public string Secret { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDeleteCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDeleteCommand.cs index 77624ec..76183bf 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDeleteCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDeleteCommand.cs @@ -1,17 +1,20 @@ -namespace Nerosoft.Starfish.Application; +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; /// /// 删除配置节点命令 /// -public class ConfigurationDeleteCommand : ConfigurationAbstractCommand +public class ConfigurationDeleteCommand : Command { /// /// 构造函数 /// - /// 应用Id - /// - public ConfigurationDeleteCommand(string appId, string environment) - : base(appId, environment) + /// 配置Id + public ConfigurationDeleteCommand(string id) { + Id = id; } + + public string Id { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDisableCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDisableCommand.cs new file mode 100644 index 0000000..7a831c5 --- /dev/null +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationDisableCommand.cs @@ -0,0 +1,13 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; + +public class ConfigurationDisableCommand : Command +{ + public ConfigurationDisableCommand(string id) + { + Id = id; + } + + public string Id { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationEnableCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationEnableCommand.cs new file mode 100644 index 0000000..ecd13cc --- /dev/null +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationEnableCommand.cs @@ -0,0 +1,13 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; + +public class ConfigurationEnableCommand : Command +{ + public ConfigurationEnableCommand(string id) + { + Id = id; + } + + public string Id { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs new file mode 100644 index 0000000..cd7c293 --- /dev/null +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs @@ -0,0 +1,25 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; + +public sealed class ConfigurationItemsUpdateCommand : Command +{ + public ConfigurationItemsUpdateCommand(string id, string mode, IDictionary items) + { + Id = id; + Mode = mode; + Items = items; + } + + public string Id { get; set; } + + /// + /// 更新方式 + /// + public string Mode { get; set; } + + /// + /// 所有配置项 + /// + public IDictionary Items { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationPublishCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationPublishCommand.cs index 14582f6..9391c26 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationPublishCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationPublishCommand.cs @@ -1,12 +1,22 @@ -namespace Nerosoft.Starfish.Application; +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; /// /// 配置节点发布命令 /// -public class ConfigurationPublishCommand : ConfigurationAbstractCommand +public class ConfigurationPublishCommand : Command { - public ConfigurationPublishCommand(string appId, string environment) - : base(appId, environment) + public ConfigurationPublishCommand(string id, string version, string comment) { + Id = id; + Version = version; + Comment = comment; } + + public string Id { get; set; } + + public string Version { get; set; } + + public string Comment { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationRevisionCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationRevisionCreateCommand.cs deleted file mode 100644 index cc42978..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationRevisionCreateCommand.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Application; - -/// -/// 创建配置版本命令 -/// -public class ConfigurationRevisionCreateCommand : ConfigurationAbstractCommand -{ - public ConfigurationRevisionCreateCommand(string appId, string environment) - : base(appId, environment) - { - } - - /// - /// 说明 - /// - public string Comment { get; set; } - - /// - /// 版本号 - /// - public string Version { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs similarity index 67% rename from Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs rename to Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs index b70faac..380be73 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs @@ -5,9 +5,9 @@ namespace Nerosoft.Starfish.Application; /// /// 设置App密钥命令 /// -public class AppInfoSetSecretCommand : Command +public class ConfigurationSetSecretCommand : Command { - public AppInfoSetSecretCommand(string id, string secret) + public ConfigurationSetSecretCommand(string id, string secret) { Id = id; Secret = secret; diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationUpdateCommand.cs index 3f816e5..4b63b4d 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationUpdateCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationUpdateCommand.cs @@ -1,13 +1,19 @@ -namespace Nerosoft.Starfish.Application; +using Nerosoft.Euonia.Domain; -public class ConfigurationUpdateCommand : ConfigurationAbstractCommand +namespace Nerosoft.Starfish.Application; + +public class ConfigurationUpdateCommand : Command { - public ConfigurationUpdateCommand(string appId, string environment) - : base(appId, environment) + public ConfigurationUpdateCommand(string id) { - AppId = appId; - Environment = environment; + Id = id; } - public IDictionary Data { get; set; } + public string Id { get; set; } + + public string Name { get; set; } + + public string Description { get; set; } + + public string Secret { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationValueUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationValueUpdateCommand.cs index a80ad5a..17b9ab3 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationValueUpdateCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationValueUpdateCommand.cs @@ -1,16 +1,18 @@ -namespace Nerosoft.Starfish.Application; +using Nerosoft.Euonia.Domain; -public class ConfigurationValueUpdateCommand : ConfigurationAbstractCommand +namespace Nerosoft.Starfish.Application; + +public class ConfigurationValueUpdateCommand : Command { - public ConfigurationValueUpdateCommand(string appId, string environment, string key, string value) - : base(appId, environment) + public ConfigurationValueUpdateCommand(string id, string key, string value) { - AppId = appId; - Environment = environment; + Id = id; Key = key; Value = value; } + public string Id { get; set; } + public string Key { get; set; } public string Value { get; set; } diff --git a/Source/Starfish.Service/Application/ConnectionContainer.cs b/Source/Starfish.Service/Application/ConnectionContainer.cs index 334220b..7db40bf 100644 --- a/Source/Starfish.Service/Application/ConnectionContainer.cs +++ b/Source/Starfish.Service/Application/ConnectionContainer.cs @@ -22,33 +22,28 @@ public ConnectionContainer(IConfigurationApplicationService service) private async void OnClientConnected(object sender, ClientConnectedEventArgs e) { - var raw = await _service.GetArchiveAsync(e.AppId, e.Environment); - var key = $"{e.AppId}-{e.Environment}"; - if (_connections.TryGetValue(key, out var connection)) + var raw = await _service.GetArchiveAsync(e.ConfigId); + if (_connections.TryGetValue(e.ConfigId, out var connection)) { await connection.Channel.Writer.WriteAsync(Tuple.Create(e.ConnectionId, raw)); } } - public ConnectionInfo GetOrAdd(string appId, string environment, string connectionId) + public ConnectionInfo GetOrAdd(string configId, string connectionId) { - var key = $"{appId}-{environment}"; - - var connection = _connections.AddOrUpdate(key, _ => ConnectionInfo.New(connectionId), (_, info) => + var connection = _connections.AddOrUpdate(configId, _ => ConnectionInfo.New(connectionId), (_, info) => { info.AddClient(connectionId); return info; }); - OnConnected?.Invoke(this, new ClientConnectedEventArgs { AppId = appId, Environment = environment, ConnectionId = connectionId }); + OnConnected?.Invoke(this, new ClientConnectedEventArgs { ConfigId = configId, ConnectionId = connectionId }); return connection; } - public void Remove(string appId, string environment, string connectionId) + public void Remove(string configId, string connectionId) { - var key = $"{appId}-{environment}"; - - if (!_connections.TryGetValue(key, out var info)) + if (!_connections.TryGetValue(configId, out var info)) { return; } @@ -56,7 +51,7 @@ public void Remove(string appId, string environment, string connectionId) info.RemoveClient(connectionId); if (info.Clients.Count == 0) { - _connections.TryRemove(key, out _); + _connections.TryRemove(configId, out _); } } @@ -64,8 +59,7 @@ public void Remove(string appId, string environment, string connectionId) public async Task HandleAsync(ConfigurationArchiveUpdatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { var aggregate = @event.GetAggregate(); - var key = $"{aggregate.AppId}-{aggregate.Environment}"; - if (_connections.TryGetValue(key, out var connection)) + if (_connections.TryGetValue(aggregate.Id, out var connection)) { await connection.Channel.Writer.WriteAsync(Tuple.Create("*", aggregate.Data), cancellationToken); } @@ -73,10 +67,7 @@ public async Task HandleAsync(ConfigurationArchiveUpdatedEvent @event, MessageCo public class ClientConnectedEventArgs : EventArgs { - public string AppId { get; set; } - - public string Environment { get; set; } - + public string ConfigId { get; set; } public string ConnectionId { get; set; } } } diff --git a/Source/Starfish.Service/Application/Contracts/IAppsApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IAppsApplicationService.cs deleted file mode 100644 index d44cc92..0000000 --- a/Source/Starfish.Service/Application/Contracts/IAppsApplicationService.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.Application; - -/// -/// 应用信息服务接口 -/// -public interface IAppsApplicationService : IApplicationService -{ - /// - /// 获取符合条件的应用列表 - /// - /// 查询条件 - /// 页码 - /// 数量 - /// - /// - Task> QueryAsync(AppInfoCriteria criteria, int skip, int count, CancellationToken cancellationToken = default); - - /// - /// 获取符合条件的应用数量 - /// - /// - /// - /// - Task CountAsync(AppInfoCriteria criteria, CancellationToken cancellationToken = default); - - /// - /// 获取应用详情 - /// - /// - /// - /// - Task GetAsync(string id, CancellationToken cancellationToken = default); - - /// - /// 应用授权 - /// - /// - /// - /// - /// - Task AuthorizeAsync(string id, string secret, CancellationToken cancellationToken = default); - - /// - /// 创建应用 - /// - /// - /// - /// - Task CreateAsync(AppInfoCreateDto data, CancellationToken cancellationToken = default); - - /// - /// 更新应用 - /// - /// - /// - /// - /// - Task UpdateAsync(string id, AppInfoUpdateDto data, CancellationToken cancellationToken = default); - - /// - /// 删除应用 - /// - /// - /// - /// - Task DeleteAsync(string id, CancellationToken cancellationToken = default); - - /// - /// 启用应用 - /// - /// - /// - /// - Task EnableAsync(string id, CancellationToken cancellationToken = default); - - /// - /// 禁用应用 - /// - /// - /// - /// - Task DisableAsync(string id, CancellationToken cancellationToken = default); - - /// - /// 设置应用密钥 - /// - /// - /// - /// - /// - Task SetSecretAsync(string id, string secret, CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs index 922c521..1483476 100644 --- a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs @@ -8,105 +8,144 @@ namespace Nerosoft.Starfish.Application; /// public interface IConfigurationApplicationService : IApplicationService { + Task> QueryAsync(ConfigurationCriteria criteria, int skip, int count, CancellationToken cancellationToken = default); + + Task CountAsync(ConfigurationCriteria criteria, CancellationToken cancellationToken = default); + /// /// 获取配置项列表 /// - /// - /// + /// + /// /// /// /// /// - Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default); + Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default); /// /// 获取配置项数量 /// - /// - /// + /// + /// /// /// - Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default); /// /// 获取配置详情 /// - /// - /// + /// /// /// - Task GetDetailAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetDetailAsync(string id, CancellationToken cancellationToken = default); /// /// 新建配置 /// - /// 应用Id - /// 应用环境 - /// + /// 团队Id /// /// /// - Task CreateAsync(string appId, string environment, string format, ConfigurationEditDto data, CancellationToken cancellationToken = default); + Task CreateAsync(string teamId, ConfigurationEditDto data, CancellationToken cancellationToken = default); /// /// 更新配置 /// - /// - /// - /// + /// /// /// /// - Task UpdateAsync(string appId, string environment, string format, ConfigurationEditDto data, CancellationToken cancellationToken = default); + Task UpdateAsync(string id, ConfigurationEditDto data, CancellationToken cancellationToken = default); /// /// 删除节点 /// - /// - /// + /// + /// + /// + Task DeleteAsync(string id, CancellationToken cancellationToken = default); + + /// + /// 设置访问密钥 + /// + /// + /// + /// + /// + Task SetSecretAsync(string id, string secret, CancellationToken cancellationToken = default); + + /// + /// 禁用配置 + /// + /// /// /// - Task DeleteAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task DisableAsync(string id, CancellationToken cancellationToken = default); + + /// + /// 启用配置 + /// + /// + /// + /// + Task EnableAsync(string id, CancellationToken cancellationToken = default); + + /// + /// 应用认证 + /// + /// + /// + /// + /// + /// + /// + Task AuthorizeAsync(string id, string teamId, string name, string secret, CancellationToken cancellationToken = default); /// /// 更新配置项 /// - /// - /// + /// /// /// /// /// - Task UpdateAsync(string appId, string environment, string key, string value, CancellationToken cancellationToken = default); + Task UpdateValueAsync(string id, string key, string value, CancellationToken cancellationToken = default); + + /// + /// 批量更新配置项 + /// + /// + /// + /// + /// + Task UpdateItemsAsync(string id, ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default); /// /// 发布配置 /// - /// - /// + /// /// /// /// - Task PublishAsync(string appId, string environment, ConfigurationPublishDto data, CancellationToken cancellationToken = default); + Task PublishAsync(string id, ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default); /// /// 获取已发布的配置 /// - /// 应用Id - /// 应用环境 + /// /// /// - Task GetArchiveAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetArchiveAsync(string id, CancellationToken cancellationToken = default); /// /// 获取指定格式的配置 /// - /// - /// + /// /// /// /// - Task GetItemsInTextAsync(string appId, string environment, string format, CancellationToken cancellationToken = default); + Task GetItemsInTextAsync(string id, string format, CancellationToken cancellationToken = default); - Task PushRedisAsync(string appId, string environment, PushRedisRequestDto data, CancellationToken cancellationToken = default); + Task PushRedisAsync(string id, ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Events/ConfigurationPublishedEvent.cs b/Source/Starfish.Service/Application/Events/ConfigurationPublishedEvent.cs deleted file mode 100644 index a6d5cb7..0000000 --- a/Source/Starfish.Service/Application/Events/ConfigurationPublishedEvent.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Nerosoft.Euonia.Domain; - -// ReSharper disable MemberCanBePrivate.Global - -namespace Nerosoft.Starfish.Application; - -/// -/// 配置节点发布完成事件 -/// -public class ConfigurationPublishedEvent : ApplicationEvent -{ - public ConfigurationPublishedEvent() - { - } - - public ConfigurationPublishedEvent(string appId, string environment) - : this() - { - AppId = appId; - Environment = environment; - } - - /// - /// 根节点Id - /// - public string AppId { get; set; } - - /// - /// 应用环境 - /// - public string Environment { get; set; } - - /// - /// 版本号 - /// - public string Version { get; set; } - - /// - /// 描述 - /// - public string Comment { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Handlers/AppInfoCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/AppInfoCommandHandler.cs deleted file mode 100644 index 067ee3a..0000000 --- a/Source/Starfish.Service/Application/Handlers/AppInfoCommandHandler.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Nerosoft.Euonia.Bus; -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Repository; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Application; - -/// -/// 应用信息命令处理器 -/// -public class AppInfoCommandHandler : CommandHandlerBase, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler -{ - /// - /// 构造函数 - /// - /// - /// - public AppInfoCommandHandler(IUnitOfWorkManager unitOfWork, IObjectFactory factory) - : base(unitOfWork, factory) - { - } - - /// - public Task HandleAsync(AppInfoCreateCommand message, MessageContext context, CancellationToken cancellationToken = default) - { - return ExecuteAsync(async () => - { - var business = await Factory.CreateAsync(cancellationToken); - - business.TeamId = message.Item1.TeamId; - business.Name = message.Item1.Name; - business.Description = message.Item1.Description; - business.Secret = message.Item1.Secret; - - business.MarkAsInsert(); - - _ = await business.SaveAsync(false, cancellationToken); - - return business.Id; - }, context.Response); - } - - /// - public Task HandleAsync(AppInfoUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) - { - return ExecuteAsync(async () => - { - var business = await Factory.FetchAsync(message.Item1, cancellationToken); - - business.Name = message.Item2.Name; - business.Description = message.Item2.Description; - - business.MarkAsUpdate(); - - _ = await business.SaveAsync(true, cancellationToken); - }); - } - - /// - public Task HandleAsync(AppInfoDeleteCommand message, MessageContext context, CancellationToken cancellationToken = default) - { - return ExecuteAsync(async () => - { - var business = await Factory.FetchAsync(message.Item1, cancellationToken); - - business.MarkAsDelete(); - - _ = await business.SaveAsync(true, cancellationToken); - }); - } - - /// - public Task HandleAsync(ChangeAppStatusCommand message, MessageContext context, CancellationToken cancellationToken = default) - { - return ExecuteAsync(async () => - { - await Factory.ExecuteAsync(message.Id, message.Status, cancellationToken); - }); - } - - /// - public Task HandleAsync(AppInfoSetSecretCommand message, MessageContext context, CancellationToken cancellationToken = default) - { - return ExecuteAsync(async () => - { - await Factory.ExecuteAsync(message.Id, message.Secret, cancellationToken); - }); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs index 5dd25d4..df1656b 100644 --- a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs +++ b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs @@ -10,13 +10,15 @@ namespace Nerosoft.Starfish.Application; /// 应用配置命令处理器 /// public class ConfigurationCommandHandler : CommandHandlerBase, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler + IHandler, + IHandler, + IHandler, + IHandler, + IHandler, + IHandler, + IHandler, + IHandler, + IHandler { public ConfigurationCommandHandler(IUnitOfWorkManager unitOfWork, IObjectFactory factory) : base(unitOfWork, factory) @@ -28,10 +30,13 @@ public Task HandleAsync(ConfigurationCreateCommand message, MessageContext conte return ExecuteAsync(async () => { var business = await Factory.CreateAsync(cancellationToken); - business.AppId = message.AppId; - business.Environment = message.Environment; - business.Items = message.Data; + business.TeamId = message.TeamId; + business.Name = message.Name; + business.Description = message.Description; + business.Secret = message.Secret; + _ = await business.SaveAsync(false, cancellationToken); + return business.Id; }, context.Response); } @@ -40,8 +45,10 @@ public Task HandleAsync(ConfigurationUpdateCommand message, MessageContext conte { return ExecuteAsync(async () => { - var business = await Factory.FetchAsync(message.AppId, message.Environment, cancellationToken); - business.Items = message.Data; + var business = await Factory.FetchAsync(message.Id, cancellationToken); + business.Name = message.Name; + business.Description = message.Description; + business.Secret = message.Secret; _ = await business.SaveAsync(true, cancellationToken); }); } @@ -51,7 +58,7 @@ public Task HandleAsync(ConfigurationDeleteCommand message, MessageContext conte { return ExecuteAsync(async () => { - var business = await Factory.FetchAsync(message.AppId, message.Environment, cancellationToken); + var business = await Factory.FetchAsync(message.Id, cancellationToken); business.MarkAsDelete(); await business.SaveAsync(false, cancellationToken); }); @@ -62,35 +69,52 @@ public Task HandleAsync(ConfigurationPublishCommand message, MessageContext cont { return ExecuteAsync(async () => { - await Factory.ExecuteAsync(message.AppId, message.Environment, cancellationToken); + await Factory.ExecuteAsync(message.Id, message.Version, message.Comment, cancellationToken); }); } + /// public Task HandleAsync(ConfigurationValueUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => { - var business = await Factory.FetchAsync(message.AppId, message.Environment, cancellationToken); - business.Key = message.Key; - business.Value = message.Value; - _ = await business.SaveAsync(true, cancellationToken); + await Factory.ExecuteAsync(message.Id, message.Key, message.Value, cancellationToken); + }); + } + + /// + public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) + { + return ExecuteAsync(async () => + { + await Factory.ExecuteAsync(message.Id, message.Items, cancellationToken); + }); + } + + /// + public Task HandleAsync(ConfigurationSetSecretCommand message, MessageContext context, CancellationToken cancellationToken = default) + { + return ExecuteAsync(async () => + { + await Factory.ExecuteAsync(message.Id, message.Secret, cancellationToken); }); } - public Task HandleAsync(ConfigurationRevisionCreateCommand message, MessageContext context, CancellationToken cancellationToken = default) + /// + public Task HandleAsync(ConfigurationDisableCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => { - var argument = new ConfigurationRevisionArgument(message.Version, message.Comment, context.User?.Identity?.Name); - await Factory.ExecuteAsync(message.AppId, message.Environment, argument, cancellationToken); + await Factory.ExecuteAsync(message.Id, false, cancellationToken); }); } - public Task HandleAsync(ConfigurationArchiveCreateCommand message, MessageContext context, CancellationToken cancellationToken = default) + /// + public Task HandleAsync(ConfigurationEnableCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => { - await Factory.ExecuteAsync(message.AppId, message.Environment, context.User?.Identity?.Name, cancellationToken); + await Factory.ExecuteAsync(message.Id, true, cancellationToken); }); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Implements/AppsApplicationService.cs b/Source/Starfish.Service/Application/Implements/AppsApplicationService.cs deleted file mode 100644 index 05bb7b8..0000000 --- a/Source/Starfish.Service/Application/Implements/AppsApplicationService.cs +++ /dev/null @@ -1,97 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Transit; -using Nerosoft.Starfish.UseCases; - -namespace Nerosoft.Starfish.Application; - -/// -/// 应用信息服务接口 -/// -public class AppsApplicationService : BaseApplicationService, IAppsApplicationService -{ - /// - public Task> QueryAsync(AppInfoCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) - { - var input = new AppInfoQueryInput(criteria, skip, count); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken) - .ContinueWith(task => task.Result.Result, cancellationToken); - } - - /// - public Task CountAsync(AppInfoCriteria criteria, CancellationToken cancellationToken = default) - { - var input = new AppInfoCountInput(criteria); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken) - .ContinueWith(task => task.Result.Count, cancellationToken); - } - - /// - public Task GetAsync(string id, CancellationToken cancellationToken = default) - { - var input = new AppInfoDetailInput(id); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken) - .ContinueWith(task => task.Result.Result, cancellationToken); - } - - /// - public Task AuthorizeAsync(string id, string secret, CancellationToken cancellationToken = default) - { - var input = new AppInfoAuthorizeInput(id, secret); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken) - .ContinueWith(task => task.Result.Result, cancellationToken); - } - - /// - public Task CreateAsync(AppInfoCreateDto data, CancellationToken cancellationToken = default) - { - var input = new AppInfoCreateInput(data); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken) - .ContinueWith(task => task.Result.Id, cancellationToken); - } - - /// - public Task UpdateAsync(string id, AppInfoUpdateDto data, CancellationToken cancellationToken = default) - { - var input = new AppInfoUpdateInput(id, data); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken); - } - - /// - public Task DeleteAsync(string id, CancellationToken cancellationToken = default) - { - var input = new AppInfoDeleteInput(id); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken); - } - - /// - public Task EnableAsync(string id, CancellationToken cancellationToken = default) - { - var input = new ChangeAppInfoStatusInput(id, AppStatus.Enabled); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken); - } - - /// - public Task DisableAsync(string id, CancellationToken cancellationToken = default) - { - var input = new ChangeAppInfoStatusInput(id, AppStatus.Disabled); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken); - } - - /// - public Task SetSecretAsync(string id, string secret, CancellationToken cancellationToken = default) - { - var input = new AppInfoSetSecretInput(id, secret); - var useCase = LazyServiceProvider.GetRequiredService(); - return useCase.ExecuteAsync(input, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs index 5bf6886..2217952 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -9,89 +9,141 @@ namespace Nerosoft.Starfish.Application; /// public class ConfigurationApplicationService : BaseApplicationService, IConfigurationApplicationService { + public Task> QueryAsync(ConfigurationCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new GenericQueryInput(criteria, skip, count); + return useCase.ExecuteAsync(input, cancellationToken) + .ContinueWith(t => t.Result.Result, cancellationToken); + } + + public Task CountAsync(ConfigurationCriteria criteria, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationCountInput(criteria); + return useCase.ExecuteAsync(input, cancellationToken) + .ContinueWith(t => t.Result.Result, cancellationToken); + } + /// - public Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default) + public Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationItemListInput(appId, environment, skip, count); + var input = new GetConfigurationItemListInput(id, key, skip, count); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } /// - public Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationItemCountInput(appId, environment); + var input = new GetConfigurationItemCountInput(id, key); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } /// - public Task GetDetailAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetDetailAsync(string id, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationDetailInput(appId, environment); + var input = new GetConfigurationDetailInput(id); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } /// - public Task CreateAsync(string appId, string environment, string format, ConfigurationEditDto data, CancellationToken cancellationToken = default) + public Task CreateAsync(string teamId, ConfigurationEditDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationCreateInput(appId, environment, format, data); + var input = new ConfigurationCreateInput(teamId, data); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result, cancellationToken); } /// - public async Task UpdateAsync(string appId, string environment, string format, ConfigurationEditDto data, CancellationToken cancellationToken = default) + public async Task UpdateAsync(string id, ConfigurationEditDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationUpdateInput(appId, environment, format, data); + var input = new ConfigurationUpdateInput(id, data); await useCase.ExecuteAsync(input, cancellationToken); } /// - public Task DeleteAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task DeleteAsync(string id, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationDeleteInput(appId, environment); + var input = new ConfigurationDeleteInput(id); + return useCase.ExecuteAsync(input, cancellationToken); + } + + public Task SetSecretAsync(string id, string secret, CancellationToken cancellationToken = default) + { + var input = new SetConfigurationSecretInput(id, secret); + var useCase = LazyServiceProvider.GetRequiredService(); return useCase.ExecuteAsync(input, cancellationToken); } + public Task DisableAsync(string id, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationDisableInput(id); + return useCase.ExecuteAsync(input, cancellationToken); + } + + public Task EnableAsync(string id, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationEnableInput(id); + return useCase.ExecuteAsync(input, cancellationToken); + } + + public Task AuthorizeAsync(string id, string teamId, string name, string secret, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationAuthorizeInput(id, teamId, name, secret); + return useCase.ExecuteAsync(input, cancellationToken) + .ContinueWith(t => t.Result.Id, cancellationToken); + } + /// - public Task UpdateAsync(string appId, string environment, string key, string value, CancellationToken cancellationToken = default) + public Task UpdateValueAsync(string id, string key, string value, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationValueUpdateInput(appId, environment, key, value); + var input = new ConfigurationValueUpdateInput(id, key, value); + return useCase.ExecuteAsync(input, cancellationToken); + } + + public Task UpdateItemsAsync(string id, ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationItemsUpdateInput(id, data); return useCase.ExecuteAsync(input, cancellationToken); } /// - public Task PublishAsync(string appId, string environment, ConfigurationPublishDto data, CancellationToken cancellationToken = default) + public Task PublishAsync(string id, ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationPublishInput(appId, environment, data); + var input = new ConfigurationPublishInput(id, data); return useCase.ExecuteAsync(input, cancellationToken); } /// - public Task GetArchiveAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetArchiveAsync(string id, CancellationToken cancellationToken = default) { - var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationRawInput(appId, environment); + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new GetConfigurationArchiveInput(id); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } /// - public Task GetItemsInTextAsync(string appId, string environment, string format, CancellationToken cancellationToken = default) + public Task GetItemsInTextAsync(string id, string format, CancellationToken cancellationToken = default) { var parser = LazyServiceProvider.GetRequiredService() .GetKeyedService(format.Normalize(TextCaseType.Lower)); - return GetItemListAsync(appId, environment, 0, int.MaxValue, cancellationToken) + return GetItemListAsync(id, string.Empty, 0, int.MaxValue, cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); @@ -101,10 +153,10 @@ public Task GetItemsInTextAsync(string appId, string environment, string }, cancellationToken); } - public Task PushRedisAsync(string appId, string environment, PushRedisRequestDto data, CancellationToken cancellationToken = default) - { - var useCase = LazyServiceProvider.GetRequiredService(); - var input = new PushRedisInput(appId, environment, data); + public Task PushRedisAsync(string id, ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationPushRedisInput(id, data); return useCase.ExecuteAsync(input, cancellationToken); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Implements/IdentityApplicationService.cs b/Source/Starfish.Service/Application/Implements/IdentityApplicationService.cs index ceb674a..63f7707 100644 --- a/Source/Starfish.Service/Application/Implements/IdentityApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/IdentityApplicationService.cs @@ -16,16 +16,9 @@ public async Task GrantAsync(string type, Dictionary await LazyServiceProvider.GetService() - .ExecuteAsync(new GrantWithPasswordUseCaseInput - { - UserName = data.GetValueOrDefault("username"), - Password = data.GetValueOrDefault("password") - }, cancellationToken), + .ExecuteAsync(new GrantWithPasswordUseCaseInput(data.GetValueOrDefault("username"), data.GetValueOrDefault("password")), cancellationToken), "refresh_token" => await LazyServiceProvider.GetService() - .ExecuteAsync(new GrantWithRefreshTokenUseCaseInput - { - Token = data.GetValueOrDefault("refresh_token") - }, cancellationToken), + .ExecuteAsync(new GrantWithRefreshTokenUseCaseInput(data.GetValueOrDefault("refresh_token")), cancellationToken), "otp" => throw new NotSupportedException(), _ => throw new NotSupportedException() }; diff --git a/Source/Starfish.Service/Application/Implements/LogsApplicationService.cs b/Source/Starfish.Service/Application/Implements/LogsApplicationService.cs index 99bb812..505ba7a 100644 --- a/Source/Starfish.Service/Application/Implements/LogsApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/LogsApplicationService.cs @@ -13,7 +13,7 @@ public class LogsApplicationService : BaseApplicationService, ILogsApplicationSe public Task> QueryAsync(OperateLogCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetService(); - return useCase.ExecuteAsync(new LogsQueryUseCaseInput(criteria, skip, count), cancellationToken) + return useCase.ExecuteAsync(new GenericQueryInput(criteria, skip, count), cancellationToken) .ContinueWith(task => task.Result.Logs, cancellationToken); } diff --git a/Source/Starfish.Service/Application/Implements/TeamApplicationService.cs b/Source/Starfish.Service/Application/Implements/TeamApplicationService.cs index a835029..f64fbfd 100644 --- a/Source/Starfish.Service/Application/Implements/TeamApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/TeamApplicationService.cs @@ -9,7 +9,7 @@ public class TeamApplicationService : BaseApplicationService, ITeamApplicationSe public Task> QueryAsync(TeamCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) { var userCase = LazyServiceProvider.GetService(); - var input = new TeamQueryInput(criteria, skip, count); + var input = new GenericQueryInput(criteria, skip, count); return userCase.ExecuteAsync(input, cancellationToken) .ContinueWith(task => task.Result.Result, cancellationToken); } diff --git a/Source/Starfish.Service/Application/Implements/UserApplicationService.cs b/Source/Starfish.Service/Application/Implements/UserApplicationService.cs index 1203c4d..6ccf283 100644 --- a/Source/Starfish.Service/Application/Implements/UserApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/UserApplicationService.cs @@ -30,7 +30,7 @@ public Task UpdateAsync(string id, UserUpdateDto data, CancellationToken cancell public Task> QueryAsync(UserCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetService(); - var input = new UserSearchInput(criteria, skip, count); + var input = new GenericQueryInput(criteria, skip, count); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(task => task.Result.Result, cancellationToken); } diff --git a/Source/Starfish.Service/Application/Mappings/AppsMappingProfile.cs b/Source/Starfish.Service/Application/Mappings/AppsMappingProfile.cs deleted file mode 100644 index 7a91a67..0000000 --- a/Source/Starfish.Service/Application/Mappings/AppsMappingProfile.cs +++ /dev/null @@ -1,30 +0,0 @@ -using AutoMapper; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Transit; -using Nerosoft.Starfish.UseCases; - -namespace Nerosoft.Starfish.Application; - -/// -/// 应用信息映射配置 -/// -internal class AppsMappingProfile : Profile -{ - /// - /// 构造函数 - /// - public AppsMappingProfile() - { - CreateMap() - .ForMember(dest => dest.StatusDescription, opt => opt.MapFrom(src => src.Status.GetDescription(Resources.ResourceManager, Resources.Culture))); - CreateMap() - .ForMember(dest => dest.StatusDescription, opt => opt.MapFrom(src => src.Status.GetDescription(Resources.ResourceManager, Resources.Culture))); - CreateMap() - .ForMember(dest => dest.StatusDescription, opt => opt.MapFrom(src => src.Status.GetDescription(Resources.ResourceManager, Resources.Culture))); - } - - private static string Mask(string source) - { - return $"{source[..3]}******{source[^3..]}"; - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs b/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs index 5677b22..9ccc295 100644 --- a/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs +++ b/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs @@ -13,9 +13,10 @@ internal class ConfigurationMappingProfile : Profile public ConfigurationMappingProfile() { CreateMap(); - CreateMap() - .ForMember(dest => dest.StatusDescription, options => options.MapFrom(src => GetStatusDescription(src.Status))) - .ForMember(dest => dest.AppName, options => options.MapFrom(src => src.App.Name)); + CreateMap() + .ForMember(dest => dest.StatusName, options => options.MapFrom(src => GetStatusDescription(src.Status))); + CreateMap(); + CreateMap(); } private static string GetStatusDescription(ConfigurationStatus status) diff --git a/Source/Starfish.Service/Application/Mappings/IdentityMappingProfile.cs b/Source/Starfish.Service/Application/Mappings/IdentityMappingProfile.cs index 3dfcd3b..e5a9b76 100644 --- a/Source/Starfish.Service/Application/Mappings/IdentityMappingProfile.cs +++ b/Source/Starfish.Service/Application/Mappings/IdentityMappingProfile.cs @@ -31,4 +31,9 @@ public IdentityMappingProfile() CreateMap(); CreateMap(); } + + private static string Mask(string source) + { + return $"{source[..3]}******{source[^3..]}"; + } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Subscribers/ConfigurationArchiveEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/ConfigurationArchiveEventSubscriber.cs deleted file mode 100644 index b9a9e61..0000000 --- a/Source/Starfish.Service/Application/Subscribers/ConfigurationArchiveEventSubscriber.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Nerosoft.Euonia.Bus; - -namespace Nerosoft.Starfish.Application; - -/// -/// 配置归档事件订阅者 -/// -public class ConfigurationArchiveEventSubscriber : IHandler -{ - private readonly IBus _bus; - - public ConfigurationArchiveEventSubscriber(IBus bus) - { - _bus = bus; - } - - /// - /// 处理配置发布事件 - /// - /// - /// - /// - /// - /// - public Task HandleAsync(ConfigurationPublishedEvent message, MessageContext context, CancellationToken cancellationToken = default) - { - var command = new ConfigurationArchiveCreateCommand - { - AppId = message.AppId, - Environment = message.Environment, - }; - - return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Subscribers/ConfigurationRevisionEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/ConfigurationRevisionEventSubscriber.cs deleted file mode 100644 index 51e9d4c..0000000 --- a/Source/Starfish.Service/Application/Subscribers/ConfigurationRevisionEventSubscriber.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Nerosoft.Euonia.Bus; - -namespace Nerosoft.Starfish.Application; - -/// -/// 配置版本事件订阅者 -/// -public class ConfigurationRevisionEventSubscriber : IHandler -{ - private readonly IBus _bus; - - public ConfigurationRevisionEventSubscriber(IBus bus) - { - _bus = bus; - } - - /// - /// 处理配置发布事件 - /// - /// - /// - /// - /// - /// - public Task HandleAsync(ConfigurationPublishedEvent message, MessageContext context, CancellationToken cancellationToken = default) - { - var command = new ConfigurationRevisionCreateCommand(message.AppId, message.Environment) - { - Version = message.Version, - Comment = message.Comment - }; - return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs index 3b2c172..9b90848 100644 --- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs +++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs @@ -8,6 +8,8 @@ namespace Nerosoft.Starfish.Application; /// public sealed class LoggingEventSubscriber { + private const string MODULE_CONFIG = "config"; + private readonly IBus _bus; public LoggingEventSubscriber(IBus bus) @@ -59,22 +61,23 @@ public Task HandleAsync(UserAuthFailedEvent @event, MessageContext context, Canc return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } - + /// - /// 处理应用创建事件 + /// 处理配置启用事件 /// /// /// /// + /// [Subscribe] - public Task HandleAsync(AppInfoCreatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) + public Task HandleAsync(ConfigurationEnabledEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var aggregate = @event.GetAggregate(); + var aggregate = @event.GetAggregate(); var command = new OperateLogCreateCommand { - Module = "apps", - Type = "create", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_CREATE, aggregate.Id, aggregate.Name), + Module = MODULE_CONFIG, + Type = "status", + Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_ENABLE, aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -84,21 +87,21 @@ public Task HandleAsync(AppInfoCreatedEvent @event, MessageContext context, Canc } /// - /// 处理应用启用事件 + /// 处理配置禁用事件 /// /// /// /// /// [Subscribe] - public Task HandleAsync(AppInfoEnabledEvent @event, MessageContext context, CancellationToken cancellationToken = default) + public Task HandleAsync(ConfigurationDisableEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var aggregate = @event.GetAggregate(); + var aggregate = @event.GetAggregate(); var command = new OperateLogCreateCommand { - Module = "apps", + Module = MODULE_CONFIG, Type = "status", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_ENABLE, aggregate.Id, aggregate.Name), + Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_DISABLE, aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -108,38 +111,21 @@ public Task HandleAsync(AppInfoEnabledEvent @event, MessageContext context, Canc } /// - /// 处理应用禁用事件 + /// 处理配置密钥重置事件 /// /// /// /// /// [Subscribe] - public Task HandleAsync(AppInfoDisableEvent @event, MessageContext context, CancellationToken cancellationToken = default) + public Task HandleAsync(ConfigurationSecretChangedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var aggregate = @event.GetAggregate(); - var command = new OperateLogCreateCommand - { - Module = "appinfo", - Type = "status", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_DISABLE, aggregate.Id, aggregate.Name), - OperateTime = DateTime.Now, - RequestTraceId = context.RequestTraceId, - UserName = context.User?.Identity?.Name - }; - - return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); - } - - [Subscribe] - public Task HandleAsync(AppInfoSecretChangedEvent @event, MessageContext context, CancellationToken cancellationToken = default) - { - var aggregate = @event.GetAggregate(); + var aggregate = @event.GetAggregate(); var command = new OperateLogCreateCommand { - Module = "apps", + Module = MODULE_CONFIG, Type = "secret", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_RESET_SECRET, aggregate.Id, aggregate.Name), + Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_RESET_SECRET, aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -148,15 +134,22 @@ public Task HandleAsync(AppInfoSecretChangedEvent @event, MessageContext context return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } + /// + /// 处理配置更新事件 + /// + /// + /// + /// + /// [Subscribe] - public Task HandleAsync(AppInfoUpdatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) + public Task HandleAsync(ConfigurationUpdatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var aggregate = @event.GetAggregate(); + var aggregate = @event.GetAggregate(); var command = new OperateLogCreateCommand { - Module = "apps", + Module = MODULE_CONFIG, Type = "update", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_UPDATE, aggregate.Id, aggregate.Name), + Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_UPDATE, aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -165,22 +158,6 @@ public Task HandleAsync(AppInfoUpdatedEvent @event, MessageContext context, Canc return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } - [Subscribe] - public Task HandleAsync(AppInfoDeletedEvent @event, MessageContext context, CancellationToken cancellationToken = default) - { - var aggregate = @event.GetAggregate(); - var command = new OperateLogCreateCommand - { - Module = "apps", - Type = "delete", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_DELETE, aggregate.Id, aggregate.Name), - OperateTime = DateTime.Now, - RequestTraceId = context.RequestTraceId, - UserName = context.User?.Identity?.Name - }; - return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); - } - /// /// 处理配置节点创建事件 /// @@ -191,11 +168,11 @@ public Task HandleAsync(AppInfoDeletedEvent @event, MessageContext context, Canc [Subscribe] public Task HandleAsync(ConfigurationCreatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_CREATE, @event.Configuration.AppId, @event.Configuration.Environment); + var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_CREATE, @event.Configuration.Id, @event.Configuration.Name); var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "create", Description = description, OperateTime = DateTime.Now, @@ -216,11 +193,11 @@ public Task HandleAsync(ConfigurationCreatedEvent @event, MessageContext context public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { var aggregate = @event.GetAggregate(); - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_DELETE, aggregate.AppId, aggregate.Environment); + var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_DELETE, aggregate.Id, aggregate.Name); var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "delete", Description = description, OperateTime = DateTime.Now, @@ -230,14 +207,22 @@ public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } + /// + /// 处理配置发布事件 + /// + /// + /// + /// + /// [Subscribe] public Task HandleAsync(ConfigurationPublishedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_PUBLISH, @event.AppId, @event.Environment); + var aggregate = @event.GetAggregate(); + var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_PUBLISH, aggregate.Id, aggregate.Name); var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "publish", Description = description, OperateTime = DateTime.Now, @@ -246,6 +231,4 @@ public Task HandleAsync(ConfigurationPublishedEvent @event, MessageContext conte }; return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } - - } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Aggregates/AppInfo.cs b/Source/Starfish.Service/Domain/Aggregates/AppInfo.cs deleted file mode 100644 index cc97276..0000000 --- a/Source/Starfish.Service/Domain/Aggregates/AppInfo.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System.Text.RegularExpressions; -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用信息 -/// -public sealed class AppInfo : Aggregate, - IHasCreateTime, - IHasUpdateTime -{ - private const string PATTERN_SECRET = @"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,32}$"; - - /// - /// 此构造方法仅提供给EntityFramework使用 - /// - private AppInfo() - { - } - - private AppInfo(string teamId) - : this() - { - TeamId = teamId; - } - - /// - /// 团队Id - /// - public string TeamId { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 密钥 - /// - public string Secret { get; set; } - - /// - /// 描述 - /// - public string Description { get; set; } - - /// - /// 状态 - /// - public AppStatus Status { get; set; } = AppStatus.Enabled; - - /// - /// 创建时间 - /// - public DateTime CreateTime { get; set; } - - /// - /// 更新时间 - /// - public DateTime UpdateTime { get; set; } - - /// - /// 创建应用 - /// - /// - /// - /// - /// - internal static AppInfo Create(string teamId, string name) - { - var entity = new AppInfo(teamId); - entity.SetName(name); - entity.RaiseEvent(new AppInfoCreatedEvent()); - return entity; - } - - /// - /// 设置名称 - /// - /// - internal void SetName(string name) - { - ArgumentNullException.ThrowIfNull(name); - Name = name; - } - - /// - /// 设置描述 - /// - /// - internal void SetDescription(string description) - { - Description = description; - } - - /// - /// 跟新应用信息 - /// - /// - /// - internal void Update(string name, string description) - { - if (string.Equals(Name, name, StringComparison.OrdinalIgnoreCase) && string.Equals(Description, description, StringComparison.OrdinalIgnoreCase)) - { - return; - } - - Name = name; - Description = description; - RaiseEvent(new AppInfoUpdatedEvent()); - } - - /// - /// 设置APP密钥 - /// - /// - /// 密钥不符合规则时引发异常 - internal void SetSecret(string secret) - { - if (string.IsNullOrWhiteSpace(secret)) - { - throw new BadRequestException(Resources.IDS_ERROR_APPINFO_SECRET_REQUIRED); - } - - if (!Regex.IsMatch(secret, PATTERN_SECRET)) - { - throw new BadRequestException(Resources.IDS_ERROR_APPINFO_SECRET_NOT_MATCHES_RULE); - } - - Secret = Cryptography.SHA.Encrypt(secret); - if (!string.IsNullOrEmpty(Id)) - { - RaiseEvent(new AppInfoSecretChangedEvent()); - } - } - - /// - /// 启用 - /// - internal void Enable() - { - if (Status == AppStatus.Enabled) - { - return; - } - - Status = AppStatus.Enabled; - RaiseEvent(new AppInfoEnabledEvent()); - } - - /// - /// 禁用 - /// - internal void Disable() - { - if (Status == AppStatus.Disabled) - { - return; - } - - Status = AppStatus.Disabled; - RaiseEvent(new AppInfoDisableEvent()); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 7d99561..7bfcb9a 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -1,4 +1,5 @@ -using Nerosoft.Euonia.Domain; +using System.Text.RegularExpressions; +using Nerosoft.Euonia.Domain; using Nerosoft.Starfish.Service; using Newtonsoft.Json; @@ -7,7 +8,7 @@ namespace Nerosoft.Starfish.Domain; /// /// 设置聚合根 /// -public sealed class Configuration : Aggregate, IAuditing +public sealed class Configuration : Aggregate, IAuditing { private Configuration() { @@ -15,17 +16,47 @@ private Configuration() { Status = @event.NewStatus; }); + Register(@event => + { + Name = @event.NewName; + }); + Register(@event => + { + Secret = @event.Secret; + }); + Register(_ => + { + SetStatus(ConfigurationStatus.Pending); + }); } + private Configuration(string teamId, string name) + : this() + { + TeamId = teamId; + Name = name; + Status = ConfigurationStatus.Pending; + } + + /// + /// 团队Id + /// + public string TeamId { get; set; } + /// - /// 应用Id + /// 配置名称 /// - public string AppId { get; set; } + public string Name { get; set; } /// - /// 应用环境 + /// 配置描述 /// - public string Environment { get; set; } + public string Description { get; set; } + + /// + /// 访问密钥 + /// + public string Secret { get; set; } /// /// 状态 @@ -67,32 +98,56 @@ private Configuration() public HashSet Revisions { get; set; } /// - /// 应用信息 + /// 配置归档 /// - public AppInfo App { get; set; } + public ConfigurationArchive Archive { get; set; } - internal static Configuration Create(string appId, string environment, IDictionary items) + internal static Configuration Create(string teamId, string name) { - var configuration = new Configuration - { - AppId = appId, - Environment = environment, - Status = ConfigurationStatus.Pending - }; - - configuration.AddOrUpdateItem(items); - + var configuration = new Configuration(teamId, name); configuration.RaiseEvent(new ConfigurationCreatedEvent(configuration)); return configuration; } - internal void AddOrUpdateItem(IDictionary items) + internal void SetName(string name) { - if (Status == ConfigurationStatus.Disabled) + EnsureStatus(); + + ArgumentException.ThrowIfNullOrWhiteSpace(name); + if (string.Equals(name, Name, StringComparison.OrdinalIgnoreCase)) + { + return; + } + + RaiseEvent(new ConfigurationNameChangedEvent(Name, name)); + } + + /// + /// 设置访问密钥 + /// + /// + /// 密钥不符合规则时引发异常 + internal void SetSecret(string secret) + { + EnsureStatus(); + + ArgumentException.ThrowIfNullOrWhiteSpace(secret); + + if (!Regex.IsMatch(secret, Constants.RegexPattern.Secret)) { - throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DISABLED); + throw new BadRequestException(Resources.IDS_ERROR_CONFIG_SECRET_NOT_MATCHES_RULE); } + if (!string.IsNullOrEmpty(Id)) + { + RaiseEvent(new ConfigurationSecretChangedEvent(Cryptography.SHA.Encrypt(secret))); + } + } + + internal void UpdateItem(IDictionary items) + { + EnsureStatus(); + Items ??= []; Items.RemoveAll(t => !items.ContainsKey(t.Key)); foreach (var (key, value) in items) @@ -109,15 +164,12 @@ internal void AddOrUpdateItem(IDictionary items) } } - Status = ConfigurationStatus.Pending; + RaiseEvent(new ConfigurationItemChangedEvent()); } internal void UpdateItem(string key, string value) { - if (Status == ConfigurationStatus.Disabled) - { - throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DISABLED); - } + EnsureStatus(); Items ??= []; @@ -128,42 +180,99 @@ internal void UpdateItem(string key, string value) throw new InvalidOperationException(string.Format(Resources.IDS_ERROR_CONFIG_KEY_NOT_EXISTS, key)); } + if (string.Equals(item.Value, value)) + { + return; + } + item.Value = value; - Status = ConfigurationStatus.Pending; + RaiseEvent(new ConfigurationItemChangedEvent()); } - internal void SetStatus(ConfigurationStatus status) + private void CreateRevision(string version, string comment, string @operator) { - if (Status == status) + Revisions ??= []; + + if (Revisions.Any(t => string.Equals(t.Version, version, StringComparison.OrdinalIgnoreCase))) { - return; + throw new InvalidOperationException(string.Format(Resources.IDS_ERROR_CONFIG_VERSION_NUMBER_EXISTS, version)); } - RaiseEvent(new ConfigurationStatusChangedEvent(Status, status)); + var data = JsonConvert.SerializeObject(Items, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + + var revision = new ConfigurationRevision(version, comment, data, @operator); + + Revisions.Add(revision); + } + + private void CreateArchive(string @operator) + { + Archive ??= ConfigurationArchive.Create(Id); + var data = Items.ToDictionary(t => t.Key, t => t.Value); + + Archive.Update(JsonConvert.SerializeObject(data), @operator); } - internal void CreateRevision(string version, string comment, string @operator) + internal void Publish(string version, string comment, string @operator) { + EnsureStatus(); + if (Items == null || Items.Count == 0) + { + throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_NO_ITEMS); + } + + CreateArchive(@operator); + CreateRevision(version, comment, @operator); + Version = version; + PublishTime = DateTime.Now; + SetStatus(ConfigurationStatus.Published); + RaiseEvent(new ConfigurationPublishedEvent()); + } + + internal void Disable() + { + if (Status == ConfigurationStatus.Disabled) { return; } - Revisions ??= []; + SetStatus(ConfigurationStatus.Disabled); + RaiseEvent(new ConfigurationDisableEvent()); + } - if (Revisions.Any(t => string.Equals(t.Version, version, StringComparison.OrdinalIgnoreCase))) + internal void Enable() + { + if (Status != ConfigurationStatus.Disabled) { - throw new InvalidOperationException(string.Format(Resources.IDS_ERROR_CONFIG_VERSION_NUMBER_EXISTS, version)); + return; } - var data = JsonConvert.SerializeObject(Items, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + SetStatus(ConfigurationStatus.Pending); + RaiseEvent(new ConfigurationEnabledEvent()); + } - var revision = new ConfigurationRevision(version, comment, data, @operator); + internal void SetDescription(string description) + { + Description = description; + } - Revisions.Add(revision); + private void EnsureStatus() + { + if (Status == ConfigurationStatus.Disabled) + { + throw new ConfigurationDisabledException(Id); + } + } - Version = version; - PublishTime = DateTime.Now; + private void SetStatus(ConfigurationStatus status) + { + if (Status == status) + { + return; + } + + RaiseEvent(new ConfigurationStatusChangedEvent(Status, status)); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Aggregates/ConfigurationArchive.cs b/Source/Starfish.Service/Domain/Aggregates/ConfigurationArchive.cs index bca3528..6d8abf9 100644 --- a/Source/Starfish.Service/Domain/Aggregates/ConfigurationArchive.cs +++ b/Source/Starfish.Service/Domain/Aggregates/ConfigurationArchive.cs @@ -5,20 +5,11 @@ namespace Nerosoft.Starfish.Domain; /// /// 配置归档 /// -public sealed class ConfigurationArchive : Aggregate +public sealed class ConfigurationArchive : Aggregate { private ConfigurationArchive() - { } - - /// - /// 应用Id - /// - public string AppId { get; set; } - - /// - /// 应用环境 - /// - public string Environment { get; set; } + { + } /// /// 配置数据 @@ -35,12 +26,13 @@ private ConfigurationArchive() /// public DateTime ArchiveTime { get; set; } - internal static ConfigurationArchive Create(string appId, string environment) + public Configuration Configuration { get; set; } + + internal static ConfigurationArchive Create(string configId) { var entity = new ConfigurationArchive() { - AppId = appId, - Environment = environment + Id = configId }; return entity; diff --git a/Source/Starfish.Service/Domain/Aggregates/ConfigurationItem.cs b/Source/Starfish.Service/Domain/Aggregates/ConfigurationItem.cs index d848602..657eb6f 100644 --- a/Source/Starfish.Service/Domain/Aggregates/ConfigurationItem.cs +++ b/Source/Starfish.Service/Domain/Aggregates/ConfigurationItem.cs @@ -25,7 +25,7 @@ internal ConfigurationItem(string key, string value) Value = value; } - public long ConfigurationId { get; set; } + public string ConfigurationId { get; set; } public string Key { get; set; } diff --git a/Source/Starfish.Service/Domain/Aggregates/ConfigurationRevision.cs b/Source/Starfish.Service/Domain/Aggregates/ConfigurationRevision.cs index 12c8241..977387c 100644 --- a/Source/Starfish.Service/Domain/Aggregates/ConfigurationRevision.cs +++ b/Source/Starfish.Service/Domain/Aggregates/ConfigurationRevision.cs @@ -20,7 +20,7 @@ internal ConfigurationRevision(string version, string comment, string data, stri Operator = @operator; } - public long ConfigurationId { get; set; } + public string ConfigurationId { get; set; } /// /// 配置数据 diff --git a/Source/Starfish.Service/Domain/Business/AppInfoGeneralBusiness.cs b/Source/Starfish.Service/Domain/Business/AppInfoGeneralBusiness.cs deleted file mode 100644 index 5ab46f6..0000000 --- a/Source/Starfish.Service/Domain/Business/AppInfoGeneralBusiness.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Domain; -using Nerosoft.Starfish.Service; - -// ReSharper disable MemberCanBePrivate.Global - -namespace Nerosoft.Starfish.Domain; - -public class AppInfoGeneralBusiness : EditableObjectBase, IDomainService -{ - [Inject] - public IAppInfoRepository AppInfoRepository { get; set; } - - [Inject] - public ITeamRepository TeamRepository { get; set; } - - internal AppInfo Aggregate { get; private set; } - - public static readonly PropertyInfo IdProperty = RegisterProperty(p => p.Id); - public static readonly PropertyInfo TeamIdProperty = RegisterProperty(p => p.TeamId); - public static readonly PropertyInfo NameProperty = RegisterProperty(p => p.Name); - public static readonly PropertyInfo SecretProperty = RegisterProperty(p => p.Secret); - public static readonly PropertyInfo DescriptionProperty = RegisterProperty(p => p.Description); - - public string Id - { - get => ReadProperty(IdProperty); - set => LoadProperty(IdProperty, value); - } - - public string TeamId - { - get => GetProperty(TeamIdProperty); - set => SetProperty(TeamIdProperty, value); - } - - public string Name - { - get => GetProperty(NameProperty); - set => SetProperty(NameProperty, value); - } - - public string Secret - { - get => GetProperty(SecretProperty); - set => SetProperty(SecretProperty, value); - } - - public string Description - { - get => GetProperty(DescriptionProperty); - set => SetProperty(DescriptionProperty, value); - } - - [FactoryCreate] - protected override Task CreateAsync(CancellationToken cancellationToken = default) - { - return Task.CompletedTask; - } - - [FactoryFetch] - protected async Task FetchAsync(string id, CancellationToken cancellationToken = default) - { - var aggregate = await AppInfoRepository.GetAsync(id, true, [], cancellationToken); - - Aggregate = aggregate ?? throw new AppInfoNotFoundException(id); - - using (BypassRuleChecks) - { - Id = aggregate.Id; - TeamId = aggregate.TeamId; - Name = aggregate.Name; - Description = aggregate.Description; - } - } - - [FactoryInsert] - protected override async Task InsertAsync(CancellationToken cancellationToken = default) - { - await CheckPermissionAsync(TeamId, cancellationToken); - - Aggregate = AppInfo.Create(TeamId, Name); - Aggregate.SetSecret(Secret); - if (!string.IsNullOrWhiteSpace(Description)) - { - Aggregate.SetDescription(Description); - } - - await AppInfoRepository.InsertAsync(Aggregate, true, cancellationToken); - Id = Aggregate.Id; - } - - [FactoryUpdate] - protected override async Task UpdateAsync(CancellationToken cancellationToken = default) - { - await CheckPermissionAsync(Aggregate.TeamId, cancellationToken); - - if (!HasChangedProperties) - { - return; - } - - if (ChangedProperties.Contains(NameProperty)) - { - Aggregate.SetName(Name); - } - - if (ChangedProperties.Contains(DescriptionProperty)) - { - Aggregate.SetDescription(Description); - } - - await AppInfoRepository.UpdateAsync(Aggregate, true, cancellationToken); - } - - [FactoryDelete] - protected override async Task DeleteAsync(CancellationToken cancellationToken = default) - { - await CheckPermissionAsync(Aggregate.TeamId, cancellationToken); - Aggregate.RaiseEvent(new AppInfoDeletedEvent()); - await AppInfoRepository.DeleteAsync(Aggregate, true, cancellationToken); - } - - private async Task CheckPermissionAsync(string teamId, CancellationToken cancellationToken = default) - { - var team = await TeamRepository.GetAsync(teamId, false, cancellationToken); - if (team.OwnerId != Identity.UserId) - { - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - } - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/AppInfoSecretBusiness.cs b/Source/Starfish.Service/Domain/Business/AppInfoSecretBusiness.cs deleted file mode 100644 index 7029beb..0000000 --- a/Source/Starfish.Service/Domain/Business/AppInfoSecretBusiness.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Claims; -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -public class AppInfoSecretBusiness : CommandObject, IDomainService -{ - [Inject] - public IAppInfoRepository AppsRepository { get; set; } - - [Inject] - public ITeamRepository TeamRepository { get; set; } - - [Inject] - private UserPrincipal Identity { get; set; } - - [FactoryExecute] - protected async Task ExecuteAsync(string id, string secret, CancellationToken cancellationToken = default) - { - var aggregate = await AppsRepository.GetAsync(id, true, cancellationToken); - if (aggregate == null) - { - throw new AppInfoNotFoundException(id); - } - - var team = await TeamRepository.GetAsync(aggregate.TeamId, false, cancellationToken); - if (team.OwnerId != Identity.UserId) - { - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - } - - aggregate.SetSecret(secret); - - await AppsRepository.UpdateAsync(aggregate, true, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/AppInfoStatusBusiness.cs b/Source/Starfish.Service/Domain/Business/AppInfoStatusBusiness.cs deleted file mode 100644 index fc21963..0000000 --- a/Source/Starfish.Service/Domain/Business/AppInfoStatusBusiness.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Claims; -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -public class AppInfoStatusBusiness : CommandObject, IDomainService -{ - [Inject] - public IAppInfoRepository AppInfoRepository { get; set; } - - [Inject] - public ITeamRepository TeamRepository { get; set; } - - [Inject] - private UserPrincipal Identity { get; set; } - - [FactoryExecute] - protected async Task ExecuteAsync(string id, AppStatus status, CancellationToken cancellationToken = default) - { - var aggregate = await AppInfoRepository.GetAsync(id, true, cancellationToken); - if (aggregate == null) - { - throw new AppInfoNotFoundException(id); - } - - var team = await TeamRepository.GetAsync(aggregate.TeamId, false, cancellationToken); - if (team.OwnerId != Identity.UserId) - { - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - } - - switch (status) - { - case AppStatus.Disabled: - aggregate.Disable(); - break; - case AppStatus.Enabled: - aggregate.Enable(); - break; - case AppStatus.None: - default: - throw new ArgumentOutOfRangeException(Resources.IDS_ERROR_APPINFO_STATUS_INVALID); - } - - await AppInfoRepository.UpdateAsync(aggregate, true, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationArchiveBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationArchiveBusiness.cs deleted file mode 100644 index d78be29..0000000 --- a/Source/Starfish.Service/Domain/Business/ConfigurationArchiveBusiness.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Domain; -using Newtonsoft.Json; - -namespace Nerosoft.Starfish.Domain; - -public class ConfigurationArchiveBusiness : CommandObject, IDomainService -{ - [Inject] - public IConfigurationRepository ConfigurationRepository { get; set; } - - [Inject] - public IConfigurationArchiveRepository ArchiveRepository { get; set; } - - [FactoryExecute] - protected async Task ExecuteAsync(string appId, string environment, string userName, CancellationToken cancellationToken = default) - { - var aggregate = await ConfigurationRepository.GetAsync(appId, environment, false, [nameof(Configuration.Items)], cancellationToken); - - if (aggregate == null) - { - throw new ConfigurationNotFoundException(appId, environment); - } - - var data = aggregate.Items.ToDictionary(t => t.Key, t => t.Value); - var json = JsonConvert.SerializeObject(data); - - var archive = await ArchiveRepository.GetAsync(appId, environment, cancellationToken); - - archive ??= ConfigurationArchive.Create(appId, environment); - - archive.Update(GzipHelper.CompressToBase64(json), userName); - - if (archive.Id > 0) - { - await ArchiveRepository.UpdateAsync(archive, true, cancellationToken); - } - else - { - await ArchiveRepository.InsertAsync(archive, true, cancellationToken); - } - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs index 6768e64..a17bf6e 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs @@ -8,54 +8,47 @@ namespace Nerosoft.Starfish.Domain; internal class ConfigurationGeneralBusiness : EditableObjectBase { [Inject] - public IAppInfoRepository AppInfoRepository { get; set; } + public ITeamRepository TeamRepository { get; set; } [Inject] public IConfigurationRepository ConfigurationRepository { get; set; } internal Configuration Aggregate { get; private set; } - public static readonly PropertyInfo IdProperty = RegisterProperty(p => p.Id); - public static readonly PropertyInfo AppIdProperty = RegisterProperty(p => p.AppId); - public static readonly PropertyInfo EnvironmentProperty = RegisterProperty(p => p.Environment); - public static readonly PropertyInfo> ItemsProperty = RegisterProperty>(p => p.Items); - public static readonly PropertyInfo KeyProperty = RegisterProperty(p => p.Key); - public static readonly PropertyInfo ValueProperty = RegisterProperty(p => p.Value); + public static readonly PropertyInfo IdProperty = RegisterProperty(p => p.Id); + public static readonly PropertyInfo TeamIdProperty = RegisterProperty(p => p.TeamId); + public static readonly PropertyInfo NameProperty = RegisterProperty(p => p.Name); + public static readonly PropertyInfo DescriptionProperty = RegisterProperty(p => p.Description); + public static readonly PropertyInfo SecretProperty = RegisterProperty(p => p.Secret); - public long Id + public string Id { get => ReadProperty(IdProperty); set => LoadProperty(IdProperty, value); } - public string AppId + public string TeamId { - get => GetProperty(AppIdProperty); - set => SetProperty(AppIdProperty, value); + get => GetProperty(TeamIdProperty); + set => SetProperty(TeamIdProperty, value); } - public string Environment + public string Name { - get => GetProperty(EnvironmentProperty); - set => SetProperty(EnvironmentProperty, value); + get => GetProperty(NameProperty); + set => SetProperty(NameProperty, value); } - public IDictionary Items + public string Description { - get => GetProperty(ItemsProperty); - set => SetProperty(ItemsProperty, value); + get => GetProperty(DescriptionProperty); + set => SetProperty(DescriptionProperty, value); } - public string Key + public string Secret { - get => GetProperty(KeyProperty); - set => SetProperty(KeyProperty, value); - } - - public string Value - { - get => GetProperty(ValueProperty); - set => SetProperty(ValueProperty, value); + get => GetProperty(SecretProperty); + set => SetProperty(SecretProperty, value); } protected override void AddRules() @@ -70,49 +63,39 @@ protected override async Task CreateAsync(CancellationToken cancellationToken = } [FactoryFetch] - protected async Task FetchAsync(string appId, string environment, CancellationToken cancellationToken = default) + protected async Task FetchAsync(string id, CancellationToken cancellationToken = default) { - var aggregate = await ConfigurationRepository.GetAsync(appId, environment, true, [nameof(Configuration.Items)], cancellationToken); + var aggregate = await ConfigurationRepository.GetAsync(id, true, [nameof(Configuration.Items)], cancellationToken); - Aggregate = aggregate ?? throw new ConfigurationNotFoundException(appId, environment); + Aggregate = aggregate ?? throw new ConfigurationNotFoundException(id); using (BypassRuleChecks) { Id = aggregate.Id; - AppId = aggregate.AppId; - Environment = aggregate.Environment; + TeamId = aggregate.TeamId; + Name = aggregate.Name; + Description = aggregate.Description; } } [FactoryInsert] protected override async Task InsertAsync(CancellationToken cancellationToken = default) { - var permission = await AppInfoRepository.CheckPermissionAsync(AppId, Identity.UserId, cancellationToken); + var permission = await TeamRepository.CheckPermissionAsync(TeamId, Identity.UserId, cancellationToken); switch (permission) { - case 0: + case PermissionState.None: // 无权限 throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - case 1: - case 2: + case PermissionState.Edit: break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); default: throw new ArgumentOutOfRangeException(); } - var appInfo = await AppInfoRepository.GetAsync(AppId, cancellationToken); - - if (appInfo == null) - { - throw new AppInfoNotFoundException(AppId); - } - - if (appInfo.Status != AppStatus.Enabled) - { - throw new AppInfoNotEnabledException(AppId); - } - - var aggregate = Configuration.Create(AppId, Environment, Items); + var aggregate = Configuration.Create(TeamId, Name); await ConfigurationRepository.InsertAsync(aggregate, true, cancellationToken); Id = aggregate.Id; } @@ -120,15 +103,16 @@ protected override async Task InsertAsync(CancellationToken cancellationToken = [FactoryUpdate] protected override async Task UpdateAsync(CancellationToken cancellationToken = default) { - var permission = await AppInfoRepository.CheckPermissionAsync(AppId, Identity.UserId, cancellationToken); + var permission = await TeamRepository.CheckPermissionAsync(Aggregate.TeamId, Identity.UserId, cancellationToken); switch (permission) { - case 0: - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - case 1: - case 2: + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(Id); + case PermissionState.Edit: break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); default: throw new ArgumentOutOfRangeException(); } @@ -138,30 +122,39 @@ protected override async Task UpdateAsync(CancellationToken cancellationToken = return; } - if (ChangedProperties.Contains(ItemsProperty)) + if (ChangedProperties.Contains(NameProperty)) + { + Aggregate.SetName(Name); + } + + if (ChangedProperties.Contains(SecretProperty)) { - Aggregate.AddOrUpdateItem(Items); + Aggregate.SetSecret(Secret); } - else if (ChangedProperties.Contains(KeyProperty) && ChangedProperties.Contains(ValueProperty)) + + if (ChangedProperties.Contains(DescriptionProperty)) { - Aggregate.UpdateItem(Key, Value); + Aggregate.SetDescription(Description); } + Aggregate.RaiseEvent(new ConfigurationUpdatedEvent()); + await ConfigurationRepository.UpdateAsync(Aggregate, true, cancellationToken); } [FactoryDelete] protected override async Task DeleteAsync(CancellationToken cancellationToken = default) { - var permission = await AppInfoRepository.CheckPermissionAsync(AppId, Identity.UserId, cancellationToken); + var permission = await TeamRepository.CheckPermissionAsync(Aggregate.TeamId, Identity.UserId, cancellationToken); switch (permission) { - case 0: - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - case 1: - case 2: + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(Id); + case PermissionState.Edit: break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); default: throw new ArgumentOutOfRangeException(); } @@ -180,10 +173,10 @@ public override async Task ExecuteAsync(IRuleContext context, CancellationToken return; } - var exists = await target.ConfigurationRepository.ExistsAsync(target.AppId, target.Environment, cancellationToken); + var exists = await target.ConfigurationRepository.ExistsAsync(target.TeamId, target.Name, cancellationToken); if (exists) { - context.AddErrorResult(string.Format(Resources.IDS_ERROR_CONFIG_DUPLICATE, target.AppId, target.Environment)); + context.AddErrorResult(string.Format(Resources.IDS_ERROR_CONFIG_DUPLICATE, target.TeamId, target.Name)); } } } diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs new file mode 100644 index 0000000..f8438fe --- /dev/null +++ b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs @@ -0,0 +1,72 @@ +using Nerosoft.Euonia.Business; +using Nerosoft.Euonia.Domain; +using Nerosoft.Starfish.Service; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationItemsBusiness : CommandObjectBase, IDomainService +{ + [Inject] + public ITeamRepository TeamRepository { get; set; } + + [Inject] + public IConfigurationRepository ConfigurationRepository { get; set; } + + [FactoryExecute] + protected async Task ExecuteAsync(string id, IDictionary items, CancellationToken cancellationToken = default) + { + var aggregate = await ConfigurationRepository.GetAsync(id, true, cancellationToken); + + if (aggregate == null) + { + throw new ConfigurationNotFoundException(id); + } + + var permission = await TeamRepository.CheckPermissionAsync(aggregate.TeamId, Identity.UserId, cancellationToken); + + switch (permission) + { + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); + } + + aggregate.UpdateItem(items); + + await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); + } + + [FactoryExecute] + protected async Task ExecuteAsync(string id, string key, string value, CancellationToken cancellationToken = default) + { + var aggregate = await ConfigurationRepository.GetAsync(id, true, cancellationToken); + + if (aggregate == null) + { + throw new ConfigurationNotFoundException(id); + } + + var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + + switch (permission) + { + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); + } + + aggregate.UpdateItem(key, value); + + await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs index b34b51c..88f937d 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs @@ -1,6 +1,7 @@ using Nerosoft.Euonia.Business; using Nerosoft.Euonia.Claims; using Nerosoft.Euonia.Domain; +using Nerosoft.Starfish.Service; // ReSharper disable UnusedMember.Global @@ -9,47 +10,41 @@ namespace Nerosoft.Starfish.Domain; /// /// 应用配置发布领域服务 /// -public class ConfigurationPublishBusiness : CommandObject, IDomainService +public class ConfigurationPublishBusiness : CommandObjectBase, IDomainService { [Inject] - public IAppInfoRepository AppInfoRepository { get; set; } + public ITeamRepository TeamRepository { get; set; } [Inject] public IConfigurationRepository ConfigurationRepository { get; set; } - [Inject] - public UserPrincipal Identity { get; set; } - [FactoryExecute] - protected async Task ExecuteAsync(string appId, string environment, CancellationToken cancellationToken = default) + protected async Task ExecuteAsync(string id, string version, string comment, CancellationToken cancellationToken = default) { - var permission = await AppInfoRepository.CheckPermissionAsync(appId, Identity.UserId, cancellationToken); + string[] includeProperties = [nameof(Configuration.Items), nameof(Configuration.Revisions), nameof(Configuration.Archive)]; - switch(permission) - { - case 0: - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - case 1: - break; - case 2: - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - default: - throw new ArgumentOutOfRangeException(); - } - - var aggregate = await ConfigurationRepository.GetAsync(appId, environment, true, [], cancellationToken); + var aggregate = await ConfigurationRepository.GetAsync(id, true, includeProperties, cancellationToken); if (aggregate == null) { - throw new ConfigurationNotFoundException(appId, environment); + throw new ConfigurationNotFoundException(id); } - if (aggregate.Status == ConfigurationStatus.Disabled) + var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + + switch (permission) { - throw new ConfigurationDisabledException(appId, environment); + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); } - aggregate.SetStatus(ConfigurationStatus.Published); + aggregate.Publish(version, comment, Identity.Username); await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); } diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationRevisionBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationRevisionBusiness.cs deleted file mode 100644 index 79d1c82..0000000 --- a/Source/Starfish.Service/Domain/Business/ConfigurationRevisionBusiness.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Nerosoft.Euonia.Business; -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -public class ConfigurationRevisionBusiness : CommandObject, IDomainService -{ - private readonly IConfigurationRepository _repository; - - public ConfigurationRevisionBusiness(IConfigurationRepository repository) - { - _repository = repository; - } - - [FactoryExecute] - protected async Task ExecuteAsync(string appId, string environment, ConfigurationRevisionArgument argument, CancellationToken cancellationToken = default) - { - var aggregate = await _repository.GetAsync(appId, environment, true, [nameof(Configuration.Items), nameof(Configuration.Revisions)], cancellationToken); - - if (aggregate == null) - { - throw new ConfigurationNotFoundException(appId, environment); - } - - aggregate.CreateRevision(argument.Version, argument.Comment, argument.Username); - await _repository.UpdateAsync(aggregate, true, cancellationToken); - } -} - -public record ConfigurationRevisionArgument(string Version, string Comment, string Username); \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationSecretBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationSecretBusiness.cs new file mode 100644 index 0000000..52a98f8 --- /dev/null +++ b/Source/Starfish.Service/Domain/Business/ConfigurationSecretBusiness.cs @@ -0,0 +1,43 @@ +using Nerosoft.Euonia.Business; +using Nerosoft.Euonia.Domain; +using Nerosoft.Starfish.Service; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationSecretBusiness : CommandObjectBase, IDomainService +{ + [Inject] + public ITeamRepository TeamRepository { get; set; } + + [Inject] + public IConfigurationRepository ConfigurationRepository { get; set; } + + [FactoryExecute] + protected async Task ExecuteAsync(string id, string secret, CancellationToken cancellationToken = default) + { + var aggregate = await ConfigurationRepository.GetAsync(id, true, cancellationToken); + + if (aggregate == null) + { + throw new ConfigurationNotFoundException(id); + } + + var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + + switch (permission) + { + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); + } + + aggregate.SetSecret(secret); + + await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationStatusBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationStatusBusiness.cs new file mode 100644 index 0000000..e39c49a --- /dev/null +++ b/Source/Starfish.Service/Domain/Business/ConfigurationStatusBusiness.cs @@ -0,0 +1,50 @@ +using Nerosoft.Euonia.Business; +using Nerosoft.Euonia.Domain; +using Nerosoft.Starfish.Service; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationStatusBusiness : CommandObjectBase, IDomainService +{ + [Inject] + public ITeamRepository TeamRepository { get; set; } + + [Inject] + public IConfigurationRepository ConfigurationRepository { get; set; } + + [FactoryExecute] + protected async Task ExecuteAsync(string id, bool availability, CancellationToken cancellationToken = default) + { + var aggregate = await ConfigurationRepository.GetAsync(id, true, cancellationToken); + + if (aggregate == null) + { + throw new ConfigurationNotFoundException(id); + } + + var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + + switch (permission) + { + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); + } + + if (availability) + { + aggregate.Enable(); + } + else + { + aggregate.Disable(); + } + + await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationValueBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationValueBusiness.cs new file mode 100644 index 0000000..ba902e9 --- /dev/null +++ b/Source/Starfish.Service/Domain/Business/ConfigurationValueBusiness.cs @@ -0,0 +1,43 @@ +using Nerosoft.Euonia.Business; +using Nerosoft.Euonia.Domain; +using Nerosoft.Starfish.Service; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationValueBusiness : CommandObjectBase, IDomainService +{ + [Inject] + public ITeamRepository TeamRepository { get; set; } + + [Inject] + public IConfigurationRepository ConfigurationRepository { get; set; } + + [FactoryExecute] + protected async Task ExecuteAsync(string id, string key, string value, CancellationToken cancellationToken = default) + { + var aggregate = await ConfigurationRepository.GetAsync(id, true, cancellationToken); + + if (aggregate == null) + { + throw new ConfigurationNotFoundException(id); + } + + var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + + switch (permission) + { + case PermissionState.None: // 无权限 + throw new ConfigurationNotFoundException(id); + case PermissionState.Edit: + break; + case PermissionState.Read: + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + default: + throw new ArgumentOutOfRangeException(); + } + + aggregate.UpdateItem(key, value); + + await ConfigurationRepository.UpdateAsync(aggregate, true, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Enums/AppStatus.cs b/Source/Starfish.Service/Domain/Enums/AppStatus.cs deleted file mode 100644 index 884c542..0000000 --- a/Source/Starfish.Service/Domain/Enums/AppStatus.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.ComponentModel; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用状态枚举 -/// -public enum AppStatus -{ - /// - /// - /// - None = 0, - - /// - /// 启用 - /// - [Description(nameof(Resources.IDS_ENUM_APPINFO_STATUS_ENABLED))] - Enabled = 1, - - /// - /// 禁用 - /// - [Description(nameof(Resources.IDS_ENUM_APPINFO_STATUS_DISABLED))] - Disabled = 2 -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoCreatedEvent.cs b/Source/Starfish.Service/Domain/Events/AppInfoCreatedEvent.cs deleted file mode 100644 index e4fb6d0..0000000 --- a/Source/Starfish.Service/Domain/Events/AppInfoCreatedEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用创建领域事件 -/// -public class AppInfoCreatedEvent : DomainEvent -{ -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoDeletedEvent.cs b/Source/Starfish.Service/Domain/Events/AppInfoDeletedEvent.cs deleted file mode 100644 index b3e4e43..0000000 --- a/Source/Starfish.Service/Domain/Events/AppInfoDeletedEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用信息删除事件 -/// -public class AppInfoDeletedEvent : DomainEvent -{ -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoSecretChangedEvent.cs b/Source/Starfish.Service/Domain/Events/AppInfoSecretChangedEvent.cs deleted file mode 100644 index 6fa87b7..0000000 --- a/Source/Starfish.Service/Domain/Events/AppInfoSecretChangedEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用信息密钥重置事件 -/// -public class AppInfoSecretChangedEvent : DomainEvent -{ -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoDisableEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationDisableEvent.cs similarity index 71% rename from Source/Starfish.Service/Domain/Events/AppInfoDisableEvent.cs rename to Source/Starfish.Service/Domain/Events/ConfigurationDisableEvent.cs index 422326f..4cfc779 100644 --- a/Source/Starfish.Service/Domain/Events/AppInfoDisableEvent.cs +++ b/Source/Starfish.Service/Domain/Events/ConfigurationDisableEvent.cs @@ -5,6 +5,6 @@ namespace Nerosoft.Starfish.Domain; /// /// 应用禁用领域事件 /// -public class AppInfoDisableEvent : DomainEvent +public class ConfigurationDisableEvent : DomainEvent { } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoEnabledEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationEnabledEvent.cs similarity index 71% rename from Source/Starfish.Service/Domain/Events/AppInfoEnabledEvent.cs rename to Source/Starfish.Service/Domain/Events/ConfigurationEnabledEvent.cs index a5e4791..7c1231a 100644 --- a/Source/Starfish.Service/Domain/Events/AppInfoEnabledEvent.cs +++ b/Source/Starfish.Service/Domain/Events/ConfigurationEnabledEvent.cs @@ -5,6 +5,6 @@ namespace Nerosoft.Starfish.Domain; /// /// 应用启用领域事件 /// -public class AppInfoEnabledEvent : DomainEvent +public class ConfigurationEnabledEvent : DomainEvent { } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/ConfigurationItemChangedEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationItemChangedEvent.cs new file mode 100644 index 0000000..83ccbe3 --- /dev/null +++ b/Source/Starfish.Service/Domain/Events/ConfigurationItemChangedEvent.cs @@ -0,0 +1,7 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationItemChangedEvent : DomainEvent +{ +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/ConfigurationNameChangedEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationNameChangedEvent.cs new file mode 100644 index 0000000..24ee3f6 --- /dev/null +++ b/Source/Starfish.Service/Domain/Events/ConfigurationNameChangedEvent.cs @@ -0,0 +1,16 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationNameChangedEvent : DomainEvent +{ + public ConfigurationNameChangedEvent(string oldName, string newName) + { + OldName = oldName; + NewName = newName; + } + + public string OldName { get; set; } + + public string NewName { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/ConfigurationPublishedEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationPublishedEvent.cs new file mode 100644 index 0000000..4375792 --- /dev/null +++ b/Source/Starfish.Service/Domain/Events/ConfigurationPublishedEvent.cs @@ -0,0 +1,7 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationPublishedEvent : DomainEvent +{ +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/ConfigurationSecretChangedEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationSecretChangedEvent.cs new file mode 100644 index 0000000..1fd5432 --- /dev/null +++ b/Source/Starfish.Service/Domain/Events/ConfigurationSecretChangedEvent.cs @@ -0,0 +1,13 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Domain; + +public class ConfigurationSecretChangedEvent : DomainEvent +{ + public ConfigurationSecretChangedEvent(string secret) + { + Secret = secret; + } + + public string Secret { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Events/AppInfoUpdatedEvent.cs b/Source/Starfish.Service/Domain/Events/ConfigurationUpdatedEvent.cs similarity index 71% rename from Source/Starfish.Service/Domain/Events/AppInfoUpdatedEvent.cs rename to Source/Starfish.Service/Domain/Events/ConfigurationUpdatedEvent.cs index 263ee98..d5b91bd 100644 --- a/Source/Starfish.Service/Domain/Events/AppInfoUpdatedEvent.cs +++ b/Source/Starfish.Service/Domain/Events/ConfigurationUpdatedEvent.cs @@ -5,6 +5,6 @@ namespace Nerosoft.Starfish.Domain; /// /// 应用信息更新事件 /// -public class AppInfoUpdatedEvent : DomainEvent +public class ConfigurationUpdatedEvent : DomainEvent { } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Exceptions/AppInfoNotEnabledException.cs b/Source/Starfish.Service/Domain/Exceptions/AppInfoNotEnabledException.cs deleted file mode 100644 index 635ca23..0000000 --- a/Source/Starfish.Service/Domain/Exceptions/AppInfoNotEnabledException.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Nerosoft.Starfish.Domain; - -public class AppInfoNotEnabledException : BadRequestException -{ - public AppInfoNotEnabledException(string appId) - : base(string.Format(Resources.IDS_ERROR_APPINFO_NOT_ENABLED, appId)) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Exceptions/AppInfoNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/AppInfoNotFoundException.cs deleted file mode 100644 index 3caf232..0000000 --- a/Source/Starfish.Service/Domain/Exceptions/AppInfoNotFoundException.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用信息不存在异常 -/// -public class AppInfoNotFoundException : NotFoundException -{ - /// - /// 构造函数 - /// - /// - public AppInfoNotFoundException(string id) - : base(string.Format(Resources.IDS_ERROR_APPINFO_NOT_EXISTS, id)) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Exceptions/ConfigurationDisabledException.cs b/Source/Starfish.Service/Domain/Exceptions/ConfigurationDisabledException.cs index 8308fe3..cd1ce7e 100644 --- a/Source/Starfish.Service/Domain/Exceptions/ConfigurationDisabledException.cs +++ b/Source/Starfish.Service/Domain/Exceptions/ConfigurationDisabledException.cs @@ -2,8 +2,8 @@ public class ConfigurationDisabledException : BadRequestException { - public ConfigurationDisabledException(string appId, string environment) - : base(string.Format(Resources.IDS_ERROR_CONFIG_DISABLED, appId, environment)) + public ConfigurationDisabledException(string id) + : base(string.Format(Resources.IDS_ERROR_CONFIG_DISABLED, id)) { } } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs index 00bd293..de42b28 100644 --- a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs +++ b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs @@ -5,13 +5,13 @@ /// public class ConfigurationNotFoundException : NotFoundException { - /// - /// 构造函数 - /// - /// 应用Id - /// 应用环境 - public ConfigurationNotFoundException(string appId, string environment) - : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, appId, environment)) + public ConfigurationNotFoundException() + : base(Resources.IDS_ERROR_CONFIG_NOT_EXISTS) + { + } + + public ConfigurationNotFoundException(string id) + : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS_OF_ID, id)) { } } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Exceptions/InvalidAppInfoStatusException.cs b/Source/Starfish.Service/Domain/Exceptions/InvalidAppInfoStatusException.cs deleted file mode 100644 index 7ff95d2..0000000 --- a/Source/Starfish.Service/Domain/Exceptions/InvalidAppInfoStatusException.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用状态无效异常 -/// -public class InvalidAppInfoStatusException : BadRequestException -{ - public InvalidAppInfoStatusException() - : base(Resources.IDS_ERROR_APPINFO_STATUS_INVALID) - { - } - - public InvalidAppInfoStatusException(string message) - : base(message) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Repositories/IAppInfoRepository.cs b/Source/Starfish.Service/Domain/Repositories/IAppInfoRepository.cs deleted file mode 100644 index 1ce6b09..0000000 --- a/Source/Starfish.Service/Domain/Repositories/IAppInfoRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Domain; - -/// -/// 应用信息仓储接口 -/// -public interface IAppInfoRepository : IBaseRepository -{ - Task CheckPermissionAsync(string appId, string userId, CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs b/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs deleted file mode 100644 index 66374f0..0000000 --- a/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Domain; - -public interface IConfigurationArchiveRepository : IBaseRepository -{ - Task GetAsync(string appId, string environment, CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs b/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs index 80322d6..96bd4af 100644 --- a/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs +++ b/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs @@ -3,20 +3,18 @@ namespace Nerosoft.Starfish.Domain; -public interface IConfigurationRepository : IBaseRepository +public interface IConfigurationRepository : IBaseRepository { /// /// 检查配置是否存在 /// - /// - /// + /// + /// /// /// - Task ExistsAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task ExistsAsync(string teamId, string name, CancellationToken cancellationToken = default); - Task GetAsync(string appId, string environment, bool tracking, string[] properties, CancellationToken cancellationToken = default); - - Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default); + Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default); - Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Repositories/IConfigurationRevisionRepository.cs b/Source/Starfish.Service/Domain/Repositories/IConfigurationRevisionRepository.cs deleted file mode 100644 index 370a52d..0000000 --- a/Source/Starfish.Service/Domain/Repositories/IConfigurationRevisionRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Domain; - -public interface IConfigurationRevisionRepository : IBaseRepository -{ -} \ No newline at end of file diff --git a/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs b/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs index b9a7df1..24bd400 100644 --- a/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs +++ b/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs @@ -14,4 +14,6 @@ public interface ITeamRepository : IBaseRepository Task> GetTeamsOfUserAsync(string userId, CancellationToken cancellationToken = default); Task> GetMembersAsync(string id, CancellationToken cancellationToken = default); + + Task CheckPermissionAsync(string id, string userId, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Source/Starfish.Service/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index c0dda26..10f0254 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -138,12 +138,6 @@ System administrator - - Disabled - - - Enabled - Disabled @@ -153,21 +147,6 @@ Published - - App not enabled, [Id]:{0}. - - - App not exists, [Id]:{0}. - - - The secret not matches rule. - - - App secret is required. - - - Invalid app status. - Authorize failed. @@ -181,10 +160,10 @@ Data format required. - Configuration was disabled, [App]:{0}, [Env]:{1}. + Configuration was disabled, [Id]:{0}. - Configuration was duplicated, [App]:{0}, [Env]:{1}. + Configuration was duplicated. Configuration key '{0}' exists. @@ -193,11 +172,26 @@ Configuration key '{0}' not exists. - Configuration not exists, [App]:{0}, [Env]:{1}. + Configuration not exists. + + + Configuration not exists, [Id]:{0}. + + + No configuration items were found. No pending item to publish. + + The secret not matches rule. + + + App secret is required. + + + Invalid app status. + Version number '{0}' already exists. @@ -264,24 +258,6 @@ UserName '{0}' not available. - - Create app {0}({1}). - - - Delete app {0}({1}). - - - Disable app {0}({1}). - - - Enable app {0}({1}). - - - Reset app secret {0}({1}). - - - Update app {0}({1}). - User authenticate failed. @@ -289,15 +265,24 @@ User authenticate successfully. - Create configuration, [App]:{0}, [Env]:{1}. + Create configuration, [Id]:{0}, [Name]:{1}. - Delete configuration, [App]:{0}, [Env]:{1}. + Delete configuration, [Id]:{0}, [Name]:{1}. + + + Disable configuration, [Id]:{0}, [Name]:{1}. + + + Enable configuration, [Id]:{0}, [Name]:{1}. - Publish configuration, [App]:{0}, [Env]:{1}. + Publish configuration, [Id]:{0}, [Name]:{1}. + + + Reset configuration secret, [Id]:{0}, [Name]:{1}. - Update configuration, [App]:{0}, [Env]:{1}. + Update configuration, [Id]:{0}, [Name]:{1}. \ No newline at end of file diff --git a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx index 66f115d..42dc9ad 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx @@ -1,17 +1,17 @@  - @@ -119,185 +119,224 @@ 开发环境 + 性能评估测试 + 生产环境 + 模拟测试 + 系统集成测试 + 用户验收测试 + 系统管理员 - - - 禁用 - - - 启用 + 禁用 + 待发布 + 已发布 - - - 应用没有启用,[Id]:{0}。 - - - 应用不存在,[Id]:{0}。 - - - 密钥不符合规则。 - - - 应用访问密钥必须提供。 - - - 无效的应用状态。 + 认证失败。 + 您无权进行此操作。 + 不支持的数据格式 '{0}'。 + 数据格式不能为空。 + - 配置已被禁用,[应用]:{0},[环境]:{1}。 + 配置已被禁用,[Id]:{0}。 + - 配置重复,[应用]:{0},[环境]:{1}。 + 配置重复。 + 配置项 '{0}' 已经存在。 + 配置项 '{0}' 不存在。 + - 配置不存在,[应用]:{0},[环境]:{1}。 + 配置不存在。 + + + 配置不存在,[Id]:{0}。 + + + + 没有找到配置项。 没有待发布的配置。 + + + + 密钥不符合规则。 + + + + 应用访问密钥必须提供。 + + + + 无效的应用状态。 + 版本号 '{0}' 已经存在。 + 请求参数'count'必须大于0。 + 请求参数'skip'不能是负数。 + 密码不正确。 + 刷新令牌已过期。 + 刷新令牌无效。 + Token不能为空。 + 团队不存在,[Id]:{0}。 + 不能移除团队负责人。 + 用户Id(s)不能为空。 + 不支持的缓存提供程序'{0}'。 + 不支持的数据库提供程序'{0}'。 + 不支持的服务总线提供程序'{0}'。 + 邮箱 '{0}' 不可用。 + 用户已锁定。 + 预留账号不允许设置角色。 + 预留账号不允许删除。 + 用户不存在,[Id]:{0}。 + 密码长度为8 ~ 32个字符,至少包含一个大写字母和一个小写字母。 + 密码不能为空。 + 用户名或密码错误。 + 用户名'{0}'不可用。 - - - 新增应用 {0}({1})。 - - - 删除应用 {0}({1})。 - - - 禁用应用 {0}({1})。 - - - 启用应用 {0}({1})。 - - - 重置应用密钥 {0}({1})。 - - - 更新应用 {0}({1})。 + 用户认证失败。 + 用户认证成功。 + - 新增配置,[应用]:{0},[环境]:{1}。 + 新增配置,[Id]:{0},[名称]:{1}。 + - 删除配置,[应用]:{0},[环境]:{1}。 + 删除配置,[Id]:{0},[名称]:{1}。 + + + + 禁用配置,[Id]:{0},[名称]:{1}。 + + + + 启用配置,[Id]:{0},[名称]:{1}。 + - 发布配置,[应用]:{0},[环境]:{1}。 + 发布配置,[Id]:{0},[名称]:{1}。 + + + + 重置访问密钥,[Id]:{0},[名称]:{1}。 + - 更新配置,[应用]:{0},[环境]:{1}。 + 更新配置,[Id]:{0},[名称]:{1}。 + \ No newline at end of file diff --git a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx index 787d1a9..c810ce7 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx @@ -1,76 +1,96 @@  - + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + - + + @@ -89,195 +109,234 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 開發環境 + 性能評估測試 + 生產環境 + 模擬測試 + 系統整合測試 + 用戶驗收測試 + 系統管理員 - - - 停用 - - - 啟用 + 停用 + 待發表 + 已發表 - - - 應用程式沒有啟用,[Id]:{0}。 - - - 應用程式不存在,[Id]:{0}。 - - - 密鑰不符合規則。 - - - 需要應用程式密鑰。 - - - 應用程式狀態無效。 + 認證失敗。 + 您無權進行此操作。 + 不支援資料格式“{0}”。 + 資料格式不能為空。 + - 設置已停用,[應用程式]:{0},[環境]:{1}。 + 配置已停用,[Id]:{0}。 + - 設置重複,[應用程式]:{0},[環境]:{1}。 + 配置重複。 + - 設置項目“{0}”已經存在。 + 配置項“{0}”已經存在。 + - 設置項目“{0}”不存在。 + 配置項“{0}”不存在。 + - 設定不存在,[應用程式]:{0},[環境]:{1}。 + 配置不存在。 + + + 配置不存在,[Id]:{0}。 + + + + 沒有找到配置項。 沒有待發布的設定。 + + + + 密鑰不符合規則。 + + + + 需要應用程式密鑰。 + + + + 應用程式狀態無效。 + 版本號碼“{0}”已存在。 + 請求參數“count”必須大於0。 + 請求參數“skip”不能為負數。 + 密碼不正確。 + 刷新令牌已過期。 + 刷新令牌無效。 + 刷新令牌不能為空。 + 團隊不存在,[Id]:{0}。 + 不能移除團隊負責人。 + 用戶Id(s)不能為空。 + 不支援的緩存提供者“{0}”。 + 不支援的資料庫提供者“{0}”。 + 不支援的服務總線提供者“{0}”。 + 電子郵件“{0}”不可用。 + 用戶被鎖定。 + 預留帳號不允許設定角色。 + 預留帳號不允許刪除。 + 用戶不存在,[Id]:{0}。 + 密碼長度必須為8-32個字符,至少包含1個大寫字母,1個小寫字母。 + 密碼不能為空。 + 用戶名或密碼錯誤。 + 用戶名“{0}”不可用。 - - - 新增應用程式 {0}({1})。 - - - 刪除應用程式 {0}({1})。 - - - 停用應用程式 {0}({1})。 - - - 啟用應用程式 {0}({1})。 - - - 重設應用程式密鑰 {0}({1})。 - - - 更新應用程式 {0}({1})。 + 用戶身份驗證失敗。 + 用戶身份驗證成功。 + - 建立設置,[應用程式]:{0},[環境]:{1}。 + 建立配置,[Id]:{0},[名稱]:{1}。 + - 刪除設置,[應用程式]:{0},[環境]:{1}。 + 刪除配置,[Id]:{0},[名稱]:{1}。 + + + + 停用配置,[Id]:{0},[名稱]:{1}。 + + + + 啟用配置,[Id]:{0},[名稱]:{1}。 + - 發佈設置,[應用程式]:{0},[環境]:{1}。 + 發佈配置,[Id]:{0},[名稱]:{1}。 + + + + 重設訪問密鑰,[Id]:{0},[名稱]:{1}。 + - 更新設置,[應用程式]:{0},[環境]:{1}。 + 更新配置,[Id]:{0},[名稱]:{1}。 + \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Contexts/AbstractDatabaseModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/AbstractDatabaseModelBuilder.cs index 0488a1d..3e8c7dd 100644 --- a/Source/Starfish.Service/Repository/Contexts/AbstractDatabaseModelBuilder.cs +++ b/Source/Starfish.Service/Repository/Contexts/AbstractDatabaseModelBuilder.cs @@ -11,7 +11,6 @@ public virtual void Configure(ModelBuilder modelBuilder) ConfigureAdministrator(modelBuilder); ConfigureTeam(modelBuilder); ConfigureTeamMember(modelBuilder); - ConfigureApplication(modelBuilder); ConfigureConfiguration(modelBuilder); ConfigureConfigurationItem(modelBuilder); ConfigureConfigurationArchive(modelBuilder); @@ -28,8 +27,6 @@ public virtual void Configure(ModelBuilder modelBuilder) protected abstract ModelBuilder ConfigureTeamMember(ModelBuilder modelBuilder); - protected abstract ModelBuilder ConfigureApplication(ModelBuilder modelBuilder); - protected abstract ModelBuilder ConfigureConfiguration(ModelBuilder modelBuilder); protected abstract ModelBuilder ConfigureConfigurationItem(ModelBuilder modelBuilder); diff --git a/Source/Starfish.Service/Repository/Contexts/DataContext.cs b/Source/Starfish.Service/Repository/Contexts/DataContext.cs index 6273d3b..dd44186 100644 --- a/Source/Starfish.Service/Repository/Contexts/DataContext.cs +++ b/Source/Starfish.Service/Repository/Contexts/DataContext.cs @@ -78,8 +78,10 @@ public override async Task SaveChangesAsync(bool acceptAllChangesOnSuccess, } } - var events = GetTrackedEvents(); var result = await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); + + var events = GetTrackedEvents(); + if (result > 0 && events.Count > 0) { var options = new PublishOptions diff --git a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs index 06d6bd0..60f1a0f 100644 --- a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs +++ b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs @@ -15,20 +15,20 @@ protected override ModelBuilder ConfigureUser(ModelBuilder modelBuilder) entity.HasKey(t => t.Id); entity.HasIndex(t => t.UserName) - .HasDatabaseName("IDX_USER_NAME") - .IsUnique(); + .HasDatabaseName("IDX_USER_NAME") + .IsUnique(); entity.HasIndex(t => t.Email) - .HasDatabaseName("IDX_USER_EMAIL") - .IsUnique(); + .HasDatabaseName("IDX_USER_EMAIL") + .IsUnique(); entity.HasIndex(t => t.Phone) - .HasDatabaseName("IDX_USER_PHONE") - .IsUnique(); + .HasDatabaseName("IDX_USER_PHONE") + .IsUnique(); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); }); } @@ -41,15 +41,15 @@ protected override ModelBuilder ConfigureAdministrator(ModelBuilder modelBuilder entity.HasKey(t => t.Id); entity.HasIndex(t => t.UserId).HasDatabaseName("IDX_ADMIN_USER_ID") - .IsUnique(); + .IsUnique(); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); entity.HasOne(t => t.User) - .WithMany() - .HasForeignKey(t => t.UserId); + .WithMany() + .HasForeignKey(t => t.UserId); }); } @@ -64,12 +64,12 @@ protected override ModelBuilder ConfigureTeam(ModelBuilder modelBuilder) entity.HasIndex(t => t.OwnerId).HasDatabaseName("IDX_TEAM_OWNER"); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); entity.HasMany(t => t.Members) - .WithOne(t => t.Team) - .HasForeignKey(t => t.TeamId); + .WithOne(t => t.Team) + .HasForeignKey(t => t.TeamId); }); } @@ -81,35 +81,19 @@ protected override ModelBuilder ConfigureTeamMember(ModelBuilder modelBuilder) entity.HasKey(t => t.Id); entity.HasIndex([nameof(TeamMember.TeamId), nameof(TeamMember.UserId)], "IDX_TEAM_MEMBER_UNIQUE") - .IsUnique(); + .IsUnique(); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); entity.HasOne(t => t.Team) - .WithMany(t => t.Members) - .HasForeignKey(t => t.TeamId); + .WithMany(t => t.Members) + .HasForeignKey(t => t.TeamId); entity.HasOne(t => t.User) - .WithMany() - .HasForeignKey(t => t.UserId); - }); - } - - protected override ModelBuilder ConfigureApplication(ModelBuilder modelBuilder) - { - return modelBuilder.Entity(entity => - { - entity.ToTable("app_info"); - entity.HasKey(t => t.Id); - - entity.HasIndex(t => t.TeamId).HasDatabaseName("IDX_APP_TEAM_ID"); - entity.HasIndex(t => t.Status).HasDatabaseName("IDX_APP_INFO_TEAM_ID"); - - entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .WithMany() + .HasForeignKey(t => t.UserId); }); } @@ -121,30 +105,31 @@ protected override ModelBuilder ConfigureConfiguration(ModelBuilder modelBuilder entity.HasKey(t => t.Id); - entity.HasIndex(t => t.AppId).HasDatabaseName("IDX_CONFIG_APP_ID"); + entity.HasIndex(t => t.TeamId).HasDatabaseName("IDX_CONFIG_TEAM_ID"); entity.HasIndex(t => t.Status).HasDatabaseName("IDX_CONFIG_STATUS"); + entity.HasIndex(t => t.Name).HasDatabaseName("IDX_CONFIG_NAME"); - entity.HasIndex([nameof(Configuration.AppId), nameof(Configuration.Environment)], "IDX_CONFIG_UNIQUE") - .IsUnique(); + entity.HasIndex([nameof(Configuration.TeamId), nameof(Configuration.Name)], "IDX_CONFIG_UNIQUE") + .IsUnique(); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); - - entity.HasOne(t => t.App) - .WithMany() - .HasForeignKey(t => t.AppId) - .OnDelete(DeleteBehavior.Cascade); + .IsRequired() + .HasValueGenerator(); entity.HasMany(t => t.Items) - .WithOne() - .HasForeignKey(t => t.ConfigurationId) - .OnDelete(DeleteBehavior.Cascade); + .WithOne() + .HasForeignKey(t => t.ConfigurationId) + .OnDelete(DeleteBehavior.Cascade); entity.HasMany(t => t.Revisions) - .WithOne() - .HasForeignKey(t => t.ConfigurationId) - .OnDelete(DeleteBehavior.Cascade); + .WithOne() + .HasForeignKey(t => t.ConfigurationId) + .OnDelete(DeleteBehavior.Cascade); + + entity.HasOne(t => t.Archive) + .WithOne() + .HasForeignKey() + .OnDelete(DeleteBehavior.Cascade); }); } @@ -158,16 +143,16 @@ protected override ModelBuilder ConfigureConfigurationItem(ModelBuilder modelBui entity.HasIndex(t => t.ConfigurationId).HasDatabaseName("IDX_CONFIG_ITEM_FK"); entity.HasIndex([nameof(ConfigurationItem.ConfigurationId), nameof(ConfigurationItem.Key)], "IDX_CONFIG_ITEM_UNIQUE") - .IsUnique(); + .IsUnique(); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); entity.HasOne(t => t.Configuration) - .WithMany(t => t.Items) - .HasForeignKey(t => t.ConfigurationId) - .OnDelete(DeleteBehavior.Cascade); + .WithMany(t => t.Items) + .HasForeignKey(t => t.ConfigurationId) + .OnDelete(DeleteBehavior.Cascade); }); } @@ -179,13 +164,8 @@ protected override ModelBuilder ConfigureConfigurationArchive(ModelBuilder model entity.HasKey(t => t.Id); - entity.HasIndex(t => t.AppId).HasDatabaseName("IDX_CONFIG_ARCHIVE_APP_ID"); - entity.HasIndex([nameof(ConfigurationArchive.AppId), nameof(ConfigurationArchive.Environment)], "IDX_CONFIG_ARCHIVE_UNIQUE") - .IsUnique(); - entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired(); }); } @@ -200,13 +180,13 @@ protected override ModelBuilder ConfigureConfigurationRevision(ModelBuilder mode entity.HasIndex(t => t.ConfigurationId).HasDatabaseName("IDS_CONFIG_REVISION_FK"); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); entity.HasOne(t => t.Configuration) - .WithMany(t => t.Revisions) - .HasForeignKey(t => t.ConfigurationId) - .OnDelete(DeleteBehavior.Cascade); + .WithMany(t => t.Revisions) + .HasForeignKey(t => t.ConfigurationId) + .OnDelete(DeleteBehavior.Cascade); }); } @@ -222,8 +202,8 @@ protected override ModelBuilder ConfigureToken(ModelBuilder modelBuilder) entity.HasIndex(t => t.Expires).HasDatabaseName("IDX_TOKEN_EXPIRES"); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); }); } @@ -240,8 +220,8 @@ protected override ModelBuilder ConfigureOperationLog(ModelBuilder modelBuilder) entity.HasIndex(t => t.UserName).HasDatabaseName("IDX_OPERATE_LOG_USER_NAME"); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); }); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/CriteriaExtensions.cs b/Source/Starfish.Service/Repository/CriteriaExtensions.cs index 50a4ab8..8be5e46 100644 --- a/Source/Starfish.Service/Repository/CriteriaExtensions.cs +++ b/Source/Starfish.Service/Repository/CriteriaExtensions.cs @@ -52,56 +52,35 @@ public static Specification GetSpecification(this OperateLogCriteria } /// - /// 获取应用信息查询规约 + /// 获取配置节点查询规约 /// /// /// - public static Specification GetSpecification(this AppInfoCriteria criteria) + public static Specification GetSpecification(this ConfigurationCriteria criteria) { - Specification specification = new TrueSpecification(); + Specification specification = new TrueSpecification(); if (criteria == null) { return specification; } - if (criteria.Status > 0) - { - var status = (AppStatus)criteria.Status; - if (status != AppStatus.None && Enum.IsDefined(status)) - { - specification &= AppInfoSpecification.StatusEquals(status); - } - } - - if (!string.IsNullOrEmpty(criteria.TeamId)) + if (!string.IsNullOrWhiteSpace(criteria.TeamId)) { - specification &= AppInfoSpecification.TeamIdEquals(criteria.TeamId); + specification &= ConfigurationSpecification.TeamIdEquals(criteria.TeamId); } if (!string.IsNullOrWhiteSpace(criteria.Keyword)) { - specification &= AppInfoSpecification.NameContains(criteria.Keyword); - } - - return specification; - } - - /// - /// 获取配置节点查询规约 - /// - /// - /// - public static Specification GetSpecification(this ConfigurationCriteria criteria) - { - Specification specification = new TrueSpecification(); - if (criteria == null) - { - return specification; + specification &= ConfigurationSpecification.Matches(criteria.Keyword); } - if (!string.IsNullOrWhiteSpace(criteria.Environment)) + if (criteria.Status > 0) { - specification &= ConfigurationSpecification.EnvironmentEquals(criteria.Environment); + var status = (ConfigurationStatus)criteria.Status; + if (status != ConfigurationStatus.None && Enum.IsDefined(status)) + { + specification &= ConfigurationSpecification.StatusEquals(status); + } } return specification; diff --git a/Source/Starfish.Service/Repository/Repositories/AppInfoRepository.cs b/Source/Starfish.Service/Repository/Repositories/AppInfoRepository.cs deleted file mode 100644 index cdea743..0000000 --- a/Source/Starfish.Service/Repository/Repositories/AppInfoRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Nerosoft.Euonia.Repository; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Repository; - -/// -/// 应用信息仓储 -/// -public class AppInfoRepository : BaseRepository, IAppInfoRepository -{ - /// - /// 构造函数 - /// - /// - public AppInfoRepository(IContextProvider provider) - : base(provider) - { - } - - public async Task CheckPermissionAsync(string appId, string userId, CancellationToken cancellationToken = default) - { - var query = from app in Context.Set() - join team in Context.Set() on app.TeamId equals team.Id - join member in Context.Set() on team.Id equals member.TeamId - where app.Id == appId - select new - { - member.UserId, - IsOwner = member.UserId == team.OwnerId - }; - - var result = await query.ToListAsync(cancellationToken); - - var user = result.FirstOrDefault(x => x.UserId == userId); - if (user == null) - { - return 0; - } - - return user.IsOwner ? 1 : 2; - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs b/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs deleted file mode 100644 index 96250df..0000000 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Nerosoft.Euonia.Linq; -using Nerosoft.Euonia.Repository; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Repository; - -public class ConfigurationArchiveRepository : BaseRepository, IConfigurationArchiveRepository -{ - public ConfigurationArchiveRepository(IContextProvider provider) - : base(provider) - { - } - - public Task GetAsync(string appId, string environment, CancellationToken cancellationToken = default) - { - ISpecification[] specs = - [ - ConfigurationArchiveSpecification.AppIdEquals(appId), - ConfigurationArchiveSpecification.EnvironmentEquals(environment) - ]; - - var specification = new CompositeSpecification(PredicateOperator.AndAlso, specs); - - var predicate = specification.Satisfy(); - - return GetAsync(predicate, true, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs b/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs index abad83a..2e9aa70 100644 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs +++ b/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; using Nerosoft.Euonia.Linq; using Nerosoft.Euonia.Repository; using Nerosoft.Starfish.Domain; @@ -6,70 +7,64 @@ namespace Nerosoft.Starfish.Repository; -public class ConfigurationRepository : BaseRepository, IConfigurationRepository +public class ConfigurationRepository : BaseRepository, IConfigurationRepository { public ConfigurationRepository(IContextProvider provider) : base(provider) { } - public Task ExistsAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task ExistsAsync(string teamId, string name, CancellationToken cancellationToken = default) { ISpecification[] specifications = [ - ConfigurationSpecification.AppIdEquals(appId), - ConfigurationSpecification.EnvironmentEquals(environment) + ConfigurationSpecification.TeamIdEquals(teamId), + ConfigurationSpecification.NameEquals(name) ]; var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); return AnyAsync(predicate, null, cancellationToken); } - public Task GetAsync(string appId, string environment, bool tracking, string[] properties, CancellationToken cancellationToken = default) + public Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default) { - ISpecification[] specifications = - [ - ConfigurationSpecification.AppIdEquals(appId), - ConfigurationSpecification.EnvironmentEquals(environment) - ]; - - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); - - return GetAsync(predicate, tracking, properties, cancellationToken); - } + var query = Context.Set() + .AsQueryable() + .AsNoTracking(); + var expressions = new List>> + { + t=>t.ConfigurationId == id + }; - public Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default) - { - ISpecification[] specifications = - [ - ConfigurationSpecification.ConfigurationAppIdEquals(appId), - ConfigurationSpecification.ConfigurationAppEnvironmentEquals(environment) - ]; + if (!string.IsNullOrWhiteSpace(key)) + { + expressions.Add(t => t.Key.Contains(key)); + } - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); + var predicate = expressions.Compose(); - var query = Context.Set() - .AsQueryable() - .Include(t => t.Configuration); return query.Where(predicate) .Skip(skip) .Take(count) .ToListAsync(cancellationToken); } - public Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default) { - ISpecification[] specifications = - [ - ConfigurationSpecification.ConfigurationAppIdEquals(appId), - ConfigurationSpecification.ConfigurationAppEnvironmentEquals(environment) - ]; + var query = Context.Set() + .AsQueryable(); + var expressions = new List>> + { + t=>t.ConfigurationId == id + }; - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); + if (!string.IsNullOrWhiteSpace(key)) + { + expressions.Add(t => t.Key.Contains(key)); + } + + var predicate = expressions.Compose(); - var query = Context.Set() - .AsQueryable() - .Include(t => t.Configuration); return query.Where(predicate).CountAsync(cancellationToken); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Repositories/ConfigurationRevisionRepository.cs b/Source/Starfish.Service/Repository/Repositories/ConfigurationRevisionRepository.cs deleted file mode 100644 index 074d822..0000000 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationRevisionRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Nerosoft.Euonia.Repository; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Service; - -namespace Nerosoft.Starfish.Repository; - -public class ConfigurationRevisionRepository : BaseRepository, IConfigurationRevisionRepository -{ - public ConfigurationRevisionRepository(IContextProvider provider) - : base(provider) - { - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs b/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs index 93f900c..e6b5904 100644 --- a/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs +++ b/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs @@ -30,4 +30,26 @@ public Task> GetMembersAsync(string id, CancellationToken cance .Where(x => x.TeamId == id); return query.ToListAsync(cancellationToken); } + + public async Task CheckPermissionAsync(string id, string userId, CancellationToken cancellationToken = default) + { + var query = from team in Context.Set() + join member in Context.Set() on team.Id equals member.TeamId + where team.Id == id + select new + { + member.UserId, + IsOwner = member.UserId == team.OwnerId + }; + + var result = await query.ToListAsync(cancellationToken); + + var user = result.FirstOrDefault(x => x.UserId == userId); + if (user == null) + { + return PermissionState.None; + } + + return user.IsOwner ? PermissionState.Edit : PermissionState.Read; + } } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/RepositoryModule.cs b/Source/Starfish.Service/Repository/RepositoryModule.cs index 424cc98..6d1688a 100644 --- a/Source/Starfish.Service/Repository/RepositoryModule.cs +++ b/Source/Starfish.Service/Repository/RepositoryModule.cs @@ -122,9 +122,6 @@ public override void ConfigureServices(ServiceConfigurationContext context) .AddScoped() .AddScoped() .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped(); + .AddScoped(); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Specifications/AppInfoSpecification.cs b/Source/Starfish.Service/Repository/Specifications/AppInfoSpecification.cs deleted file mode 100644 index 0dad1ed..0000000 --- a/Source/Starfish.Service/Repository/Specifications/AppInfoSpecification.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Nerosoft.Euonia.Linq; -using Nerosoft.Starfish.Domain; - -namespace Nerosoft.Starfish.Repository; - -/// -/// 应用信息查询规约 -/// -internal static class AppInfoSpecification -{ - /// - /// Id等于 - /// - /// - /// - public static Specification IdEquals(string id) - { - return new DirectSpecification(t => t.Id == id); - } - - /// - /// 团队Id等于 - /// - /// - /// - public static Specification TeamIdEquals(string teamId) - { - return new DirectSpecification(t => t.TeamId == teamId); - } - - /// - /// 应用名称等于 - /// - /// - /// - public static Specification NameEquals(string name) - { - name = name.Normalize(TextCaseType.Lower); - return new DirectSpecification(t => t.Name.ToLower() == name); - } - - /// - /// 应用名称包含 - /// - /// - /// - public static Specification NameContains(string name) - { - name = name.Normalize(TextCaseType.Lower); - return new DirectSpecification(t => t.Name.ToLower().Contains(name)); - } - - /// - /// 应用描述包含 - /// - /// - /// - public static Specification DescriptionContains(string description) - { - description = description.Normalize(TextCaseType.Lower); - return new DirectSpecification(t => t.Description.Contains(description)); - } - - /// - /// 状态等于 - /// - /// - /// - public static Specification StatusEquals(AppStatus status) - { - return new DirectSpecification(t => t.Status == status); - } - - /// - /// 匹配关键字 - /// - /// - /// - public static Specification Matches(string keyword) - { - var nameSpecification = NameContains(keyword); - var descSpecification = DescriptionContains(keyword); - - return nameSpecification | descSpecification; - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Specifications/ConfigurationArchiveSpecification.cs b/Source/Starfish.Service/Repository/Specifications/ConfigurationArchiveSpecification.cs index 7eb27fa..c5ea423 100644 --- a/Source/Starfish.Service/Repository/Specifications/ConfigurationArchiveSpecification.cs +++ b/Source/Starfish.Service/Repository/Specifications/ConfigurationArchiveSpecification.cs @@ -5,14 +5,14 @@ namespace Nerosoft.Starfish.Repository; internal static class ConfigurationArchiveSpecification { - public static Specification AppIdEquals(string appId) + public static Specification TeamIdEquals(string teamId) { - return new DirectSpecification(x => x.AppId == appId); + return new DirectSpecification(x => x.Configuration.TeamId == teamId); } - public static Specification EnvironmentEquals(string environment) + public static Specification NameEquals(string name) { - environment = environment.Normalize(TextCaseType.Upper); - return new DirectSpecification(x => x.Environment == environment); + name = name.Normalize(TextCaseType.Upper); + return new DirectSpecification(x => x.Configuration.Name == name); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Specifications/ConfigurationSpecification.cs b/Source/Starfish.Service/Repository/Specifications/ConfigurationSpecification.cs index 60c2f5f..f7b8bb4 100644 --- a/Source/Starfish.Service/Repository/Specifications/ConfigurationSpecification.cs +++ b/Source/Starfish.Service/Repository/Specifications/ConfigurationSpecification.cs @@ -5,33 +5,47 @@ namespace Nerosoft.Starfish.Repository; internal static class ConfigurationSpecification { - public static Specification IdEquals(long id) + public static Specification IdEquals(string id) { return new DirectSpecification(x => x.Id == id); } - public static Specification AppIdEquals(string appId) + public static Specification TeamIdEquals(string appId) { - return new DirectSpecification(x => x.AppId == appId); + return new DirectSpecification(x => x.TeamId == appId); } - public static Specification EnvironmentEquals(string environment) + public static Specification NameEquals(string name) { - return new DirectSpecification(x => x.Environment == environment); + name = name.Normalize(TextCaseType.Lower); + return new DirectSpecification(x => x.Name.ToLower() == name); } - public static Specification StatusEquals(ConfigurationStatus status) + public static Specification NameContains(string name) { - return new DirectSpecification(x => x.Status == status); + name = name.Normalize(TextCaseType.Lower); + return new DirectSpecification(x => x.Name.ToLower().Contains(name)); + } + + public static Specification DescriptionContains(string description) + { + description = description.Normalize(TextCaseType.Lower); + return new DirectSpecification(x => x.Description.ToLower().Contains(description)); } - public static Specification ConfigurationAppIdEquals(string appId) + public static Specification StatusEquals(ConfigurationStatus status) { - return new DirectSpecification(x => x.Configuration.AppId == appId); + return new DirectSpecification(x => x.Status == status); } - public static Specification ConfigurationAppEnvironmentEquals(string environment) + public static Specification Matches(string keyword) { - return new DirectSpecification(x => x.Configuration.Environment == environment); + var specifications = new List> + { + NameContains(keyword), + DescriptionContains(keyword) + }; + + return new CompositeSpecification(PredicateOperator.OrElse, specifications.ToArray()); } } \ No newline at end of file diff --git a/Source/Starfish.Service/Seedwork/CommandObjectBase.cs b/Source/Starfish.Service/Seedwork/CommandObjectBase.cs new file mode 100644 index 0000000..c1b962e --- /dev/null +++ b/Source/Starfish.Service/Seedwork/CommandObjectBase.cs @@ -0,0 +1,18 @@ +using Nerosoft.Euonia.Business; +using Nerosoft.Euonia.Claims; + +namespace Nerosoft.Starfish.Service; + +public abstract class CommandObjectBase : CommandObject, IHasLazyServiceProvider + where T : CommandObjectBase +{ + /// + /// 懒加载服务提供程序 + /// + public ILazyServiceProvider LazyServiceProvider { get; set; } + + /// + /// 当前授权用户信息 + /// + protected virtual UserPrincipal Identity => LazyServiceProvider.GetRequiredService(); +} \ No newline at end of file diff --git a/Source/Starfish.Service/Starfish.Service.csproj b/Source/Starfish.Service/Starfish.Service.csproj index 42a7642..d166299 100644 --- a/Source/Starfish.Service/Starfish.Service.csproj +++ b/Source/Starfish.Service/Starfish.Service.csproj @@ -33,6 +33,7 @@ + diff --git a/Source/Starfish.Service/UseCases/Admins/AdministratorDeleteUseCase.cs b/Source/Starfish.Service/UseCases/Admins/AdministratorDeleteUseCase.cs index cdf5930..c278b4c 100644 --- a/Source/Starfish.Service/UseCases/Admins/AdministratorDeleteUseCase.cs +++ b/Source/Starfish.Service/UseCases/Admins/AdministratorDeleteUseCase.cs @@ -20,7 +20,7 @@ public AdministratorDeleteUseCase(IBus bus, UserPrincipal user) _user = user; } - public Task ExecuteAsync(AdministratorDeleteInput input, CancellationToken cancellationToken = new CancellationToken()) + public Task ExecuteAsync(AdministratorDeleteInput input, CancellationToken cancellationToken = default) { _user.EnsureInRoles(["SA"]); diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoAuthorizeUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoAuthorizeUseCase.cs deleted file mode 100644 index ef73632..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoAuthorizeUseCase.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Starfish.Domain; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用信息认证用例接口 -/// -public interface IAppInfoAuthorizeUseCase : IUseCase; - -/// -/// 应用信息认证输入 -/// -/// -/// -public record AppInfoAuthorizeInput(string Id, string Secret) : IUseCaseInput; - -/// -/// 应用信息认证输出 -/// -/// -public record AppInfoAuthorizeOutput(bool Result) : IUseCaseOutput; - -/// -/// 应用信息认证用例 -/// -public class AppInfoAuthorizeUseCase : IAppInfoAuthorizeUseCase -{ - private readonly IAppInfoRepository _repository; - - /// - /// 构造函数 - /// - /// - public AppInfoAuthorizeUseCase(IAppInfoRepository repository) - { - _repository = repository; - } - - /// - public async Task ExecuteAsync(AppInfoAuthorizeInput input, CancellationToken cancellationToken = default) - { - var appInfo = await _repository.GetAsync(input.Id, cancellationToken); - if (appInfo == null) - { - throw new AppInfoNotFoundException(input.Id); - } - - var encryptedSecret = Cryptography.SHA.Encrypt(input.Secret); - - var result = string.Equals(appInfo.Secret, encryptedSecret); - - return new AppInfoAuthorizeOutput(result); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoCountUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoCountUseCase.cs deleted file mode 100644 index 6b8fe84..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoCountUseCase.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用数量查询用例接口 -/// -public interface IAppInfoCountUseCase : IUseCase; - -/// -/// 应用数量查询用例输出 -/// -/// -public record AppInfoCountOutput(int Count) : IUseCaseOutput; - -/// -/// 应用数量查询用例输入 -/// -/// -public record AppInfoCountInput(AppInfoCriteria Criteria) : IUseCaseInput; - -/// -/// 应用数量查询用例 -/// -public class AppInfoCountUseCase : IAppInfoCountUseCase -{ - private readonly IAppInfoRepository _repository; - private readonly UserPrincipal _user; - - /// - /// 构造函数 - /// - /// - /// - public AppInfoCountUseCase(IAppInfoRepository repository, UserPrincipal user) - { - _repository = repository; - _user = user; - } - - /// - public async Task ExecuteAsync(AppInfoCountInput input, CancellationToken cancellationToken = default) - { - var predicate = input.Criteria.GetSpecification().Satisfy(); - var count = await _repository.CountAsync(predicate, Permission, cancellationToken); - return new AppInfoCountOutput(count); - - IQueryable Permission(IQueryable query) - { - if (!_user.IsInRole("SA")) - { - var teamQuery = _repository.Context.Set(); - query = from app in query - join member in teamQuery on app.TeamId equals member.TeamId - where member.UserId == _user.UserId - select app; - } - - { - } - - return query; - } - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoCreateUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoCreateUseCase.cs deleted file mode 100644 index 816d292..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoCreateUseCase.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Bus; -using Nerosoft.Starfish.Application; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 创建应用信息用例接口 -/// -public interface IAppInfoCreateUseCase : IUseCase; - -/// -/// 创建应用信息用例输出 -/// -/// -public record AppInfoCreateOutput(string Id) : IUseCaseOutput; - -/// -/// 创建应用信息用例输入 -/// -/// -public record AppInfoCreateInput(AppInfoCreateDto Data) : IUseCaseInput; - -/// -/// 创建应用信息用例 -/// -public class AppInfoCreateUseCase : IAppInfoCreateUseCase -{ - private readonly IBus _bus; - - /// - /// 构造函数 - /// - /// - public AppInfoCreateUseCase(IBus bus) - { - _bus = bus; - } - - /// - public Task ExecuteAsync(AppInfoCreateInput input, CancellationToken cancellationToken = default) - { - var command = new AppInfoCreateCommand(input.Data); - return _bus.SendAsync(command, cancellationToken) - .ContinueWith(task => - { - task.WaitAndUnwrapException(cancellationToken); - return new AppInfoCreateOutput(task.Result); - }, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoDeleteUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoDeleteUseCase.cs deleted file mode 100644 index 1a67fa4..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoDeleteUseCase.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Security.Authentication; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Bus; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Application; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用信息删除用例接口 -/// -public interface IAppInfoDeleteUseCase : INonOutputUseCase; - -/// -/// 应用信息删除输入 -/// -/// -public record AppInfoDeleteInput(string Id) : IUseCaseInput; - -/// -/// 应用信息删除用例 -/// -public class AppInfoDeleteUseCase : IAppInfoDeleteUseCase -{ - /// - /// 允许访问的角色 - /// - private readonly string[] _roles = ["SA", "RW"]; - - private readonly IBus _bus; - private readonly UserPrincipal _user; - - public AppInfoDeleteUseCase(IBus bus, UserPrincipal user) - { - _bus = bus; - _user = user; - } - - public Task ExecuteAsync(AppInfoDeleteInput input, CancellationToken cancellationToken = default) - { - if (!_user.IsAuthenticated) - { - throw new AuthenticationException(); - } - - if (!_user.IsInRoles(_roles)) - { - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - } - - var command = new AppInfoDeleteCommand(input.Id); - return _bus.SendAsync(command, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoDetailUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoDetailUseCase.cs deleted file mode 100644 index aad38a1..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoDetailUseCase.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Security.Authentication; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用详情查询用例接口 -/// -public interface IAppInfoDetailUseCase : IUseCase; - -/// -/// 应用详情查询用例输出 -/// -/// -public record AppInfoDetailOutput(AppInfoDetailDto Result) : IUseCaseOutput; - -/// -/// 应用详情查询用例输入 -/// -/// -public record AppInfoDetailInput(string Id) : IUseCaseInput; - -/// -/// 应用详情查询用例 -/// -public class AppInfoDetailUseCase : IAppInfoDetailUseCase -{ - private readonly IAppInfoRepository _repository; - private readonly UserPrincipal _user; - - /// - /// 构造函数 - /// - /// - /// - public AppInfoDetailUseCase(IAppInfoRepository repository, UserPrincipal user) - { - _repository = repository; - _user = user; - } - - /// - public Task ExecuteAsync(AppInfoDetailInput input, CancellationToken cancellationToken = default) - { - if (!_user.IsAuthenticated) - { - throw new AuthenticationException(); - } - - var predicate = AppInfoSpecification.IdEquals(input.Id).Satisfy(); - return _repository.GetAsync(predicate, Permission, cancellationToken) - .ContinueWith(task => new AppInfoDetailOutput(task.Result.ProjectedAs()), cancellationToken); - - IQueryable Permission(IQueryable query) - { - if (!_user.IsInRole("SA")) - { - var teamQuery = _repository.Context.Set(); - query = from app in query - join member in teamQuery on app.TeamId equals member.TeamId - where member.UserId == _user.UserId - select app; - } - - { - } - - return query; - } - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoQueryUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoQueryUseCase.cs deleted file mode 100644 index 26408f7..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoQueryUseCase.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System.Security.Authentication; -using Microsoft.EntityFrameworkCore; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Repository; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用信息搜索用例接口 -/// -public interface IAppInfoQueryUseCase : IUseCase; - -/// -/// 应用信息搜索用例输入 -/// -/// -/// -/// -public record AppInfoQueryInput(AppInfoCriteria Criteria, int Skip, int Count) : IUseCaseInput; - -/// -/// 应用信息搜索用例输出 -/// -/// -public record AppInfoQueryOutput(List Result) : IUseCaseOutput; - -/// -/// 应用信息搜索用例 -/// -public class AppInfoQueryUseCase : IAppInfoQueryUseCase -{ - private readonly IAppInfoRepository _repository; - private readonly UserPrincipal _identity; - - /// - /// 构造函数 - /// - /// - /// - /// - public AppInfoQueryUseCase(IAppInfoRepository repository, UserPrincipal identity) - { - _repository = repository; - _identity = identity; - } - - /// - public Task ExecuteAsync(AppInfoQueryInput input, CancellationToken cancellationToken = default) - { - if (input.Skip < 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_SKIP_CANNOT_BE_NEGATIVE); - } - - if (input.Count <= 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_COUNT_MUST_GREATER_THAN_0); - } - - if (!_identity.IsAuthenticated) - { - throw new AuthenticationException(); - } - - var predicate = input.Criteria.GetSpecification().Satisfy(); - - var context = _repository.Context; - - var query = from app in context.Set().Where(predicate) - join team in context.Set() on app.TeamId equals team.Id - select new AppInfoItemModel - { - Id = app.Id, - TeamId = app.TeamId, - TeamName = team.Name, - Name = app.Name, - Status = app.Status, - CreateTime = app.CreateTime, - UpdateTime = app.UpdateTime - }; - - if (!_identity.IsInRole("SA")) - { - var teamQuery = _repository.Context.Set(); - query = from app in query - join member in teamQuery on app.TeamId equals member.TeamId - where member.UserId == _identity.UserId - select app; - } - - { - } - - return query.OrderByDescending(t => t.Id) - .ToListAsync(cancellationToken) - .ContinueWith(task => - { - task.WaitAndUnwrapException(cancellationToken); - var result = task.Result.ProjectedAsCollection(); - return new AppInfoQueryOutput(result); - }, cancellationToken); - } -} - -internal class AppInfoItemModel -{ - public string Id { get; set; } - public string TeamId { get; set; } - public string TeamName { get; set; } - public string Name { get; set; } - public AppStatus Status { get; set; } - public DateTime CreateTime { get; set; } - public DateTime UpdateTime { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoSetSecretUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoSetSecretUseCase.cs deleted file mode 100644 index 51740f1..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoSetSecretUseCase.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Bus; -using Nerosoft.Starfish.Application; - -namespace Nerosoft.Starfish.UseCases; - -public interface IAppInfoSetSecretUseCase : INonOutputUseCase; - -public record AppInfoSetSecretInput(string Id, string Secret) : IUseCaseInput; - -public class AppInfoSetSecretUseCase : IAppInfoSetSecretUseCase -{ - private readonly IBus _bus; - - public AppInfoSetSecretUseCase(IBus bus) - { - _bus = bus; - } - - public Task ExecuteAsync(AppInfoSetSecretInput input, CancellationToken cancellationToken = default) - { - var command = new AppInfoSetSecretCommand(input.Id, input.Secret); - return _bus.SendAsync(command, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/AppInfoUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Apps/AppInfoUpdateUseCase.cs deleted file mode 100644 index 49ef91c..0000000 --- a/Source/Starfish.Service/UseCases/Apps/AppInfoUpdateUseCase.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Security.Authentication; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Bus; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Application; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 应用信息更新用例接口 -/// -public interface IAppInfoUpdateUseCase : INonOutputUseCase; - -/// -/// 应用信息更新输入 -/// -/// -/// -public record AppInfoUpdateInput(string Id, AppInfoUpdateDto Model) : IUseCaseInput; - -/// -/// 应用信息更新用例 -/// -public class AppInfoUpdateUseCase : IAppInfoUpdateUseCase -{ - private readonly IBus _bus; - private readonly UserPrincipal _user; - - public AppInfoUpdateUseCase(IBus bus, UserPrincipal user) - { - _bus = bus; - _user = user; - } - - public Task ExecuteAsync(AppInfoUpdateInput input, CancellationToken cancellationToken = default) - { - if (!_user.IsAuthenticated) - { - throw new AuthenticationException(); - } - - var command = new AppInfoUpdateCommand(input.Id, input.Model); - return _bus.SendAsync(command, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Apps/ChangeAppInfoStatusUseCase.cs b/Source/Starfish.Service/UseCases/Apps/ChangeAppInfoStatusUseCase.cs deleted file mode 100644 index fc4dfbd..0000000 --- a/Source/Starfish.Service/UseCases/Apps/ChangeAppInfoStatusUseCase.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Security.Authentication; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Bus; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Application; -using Nerosoft.Starfish.Domain; - -namespace Nerosoft.Starfish.UseCases; - -/// -/// 变更应用信息状态用例接口 -/// -public interface IChangeAppInfoStatusUseCase : INonOutputUseCase; - -/// -/// 变更应用信息状态输入 -/// -/// -/// -public record ChangeAppInfoStatusInput(string Id, AppStatus Status) : IUseCaseInput; - -/// -/// 变更应用信息状态用例 -/// -public class ChangeAppInfoStatusUseCase : IChangeAppInfoStatusUseCase -{ - private readonly IBus _bus; - private readonly UserPrincipal _user; - - public ChangeAppInfoStatusUseCase(IBus bus, UserPrincipal user) - { - _bus = bus; - _user = user; - } - - public Task ExecuteAsync(ChangeAppInfoStatusInput input, CancellationToken cancellationToken = default) - { - if (!_user.IsAuthenticated) - { - throw new AuthenticationException(); - } - - var command = new ChangeAppStatusCommand(input.Id, input.Status); - return _bus.SendAsync(command, cancellationToken); - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs new file mode 100644 index 0000000..6f3e615 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs @@ -0,0 +1,59 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Linq; +using Nerosoft.Starfish.Domain; +using Nerosoft.Starfish.Repository; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationAuthorizeUseCase : IUseCase; + +internal record ConfigurationAuthorizeInput(string Id, string TeamId, string Name, string Secret) : IUseCaseInput; + +internal record ConfigurationAuthorizeOutput(string Id) : IUseCaseOutput; + +internal class ConfigurationAuthorizeUseCase : IConfigurationAuthorizeUseCase +{ + private readonly IConfigurationRepository _repository; + + public ConfigurationAuthorizeUseCase(IConfigurationRepository repository) + { + _repository = repository; + } + + public async Task ExecuteAsync(ConfigurationAuthorizeInput input, CancellationToken cancellationToken = default) + { + Specification specification; + if (!string.IsNullOrEmpty(input.Id)) + { + specification = ConfigurationSpecification.IdEquals(input.Id); + } + else if (!string.IsNullOrEmpty(input.TeamId) && !string.IsNullOrEmpty(input.Name)) + { + specification = new CompositeSpecification(PredicateOperator.AndAlso, + ConfigurationSpecification.TeamIdEquals(input.TeamId), + ConfigurationSpecification.NameEquals(input.Name)); + } + else + { + throw new ArgumentException("Id, or TeamId and Name must be provided"); + } + + var predicate = specification.Satisfy(); + + var configuration = await _repository.GetAsync(predicate, false, cancellationToken); + + if (configuration == null) + { + throw new ConfigurationNotFoundException(); + } + + var encryptedSecret = Cryptography.SHA.Encrypt(input.Secret); + + if (!string.Equals(configuration.Secret, encryptedSecret)) + { + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_AUTHORIZE_FAILED); + } + + return new ConfigurationAuthorizeOutput(configuration.Id); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs new file mode 100644 index 0000000..56a9aa4 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs @@ -0,0 +1,34 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Starfish.Domain; +using Nerosoft.Starfish.Repository; +using Nerosoft.Starfish.Transit; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationCountUseCase : IUseCase; + +internal record ConfigurationCountInput(ConfigurationCriteria Criteria) : IUseCaseInput; + +internal record ConfigurationCountOutput(int Result) : IUseCaseOutput; + +internal class ConfigurationCountUseCase : IConfigurationCountUseCase +{ + private readonly IConfigurationRepository _repository; + + public ConfigurationCountUseCase(IConfigurationRepository repository) + { + _repository = repository; + } + + public Task ExecuteAsync(ConfigurationCountInput input, CancellationToken cancellationToken = default) + { + var specification = input.Criteria.GetSpecification(); + var predicate = specification.Satisfy(); + return _repository.CountAsync(predicate, cancellationToken) + .ContinueWith(task => + { + task.WaitAndUnwrapException(cancellationToken); + return new ConfigurationCountOutput(task.Result); + }, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs index 57dfd47..76f76ee 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs @@ -1,44 +1,31 @@ using Nerosoft.Euonia.Application; using Nerosoft.Euonia.Bus; +using Nerosoft.Euonia.Mapping; using Nerosoft.Starfish.Application; using Nerosoft.Starfish.Transit; namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationCreateUseCase : IUseCase; +internal interface IConfigurationCreateUseCase : IUseCase; -public record ConfigurationCreateInput(string AppId, string Environment, string Format, ConfigurationEditDto Data) : IUseCaseInput; +internal record ConfigurationCreateInput(string TeamId, ConfigurationEditDto Data) : IUseCaseInput; -public class ConfigurationCreateUseCase : IConfigurationCreateUseCase +internal class ConfigurationCreateUseCase : IConfigurationCreateUseCase { private readonly IBus _bus; - private readonly IServiceProvider _provider; - public ConfigurationCreateUseCase(IBus bus, IServiceProvider provider) + public ConfigurationCreateUseCase(IBus bus) { _bus = bus; - _provider = provider; } - public Task ExecuteAsync(ConfigurationCreateInput input, CancellationToken cancellationToken = default) + public Task ExecuteAsync(ConfigurationCreateInput input, CancellationToken cancellationToken = default) { - var format = input.Format?.Normalize(TextCaseType.Lower).Trim(TextTrimType.All); - var parserName = format switch - { - Constants.Configuration.FormatText => "text", - Constants.Configuration.FormatJson => "json", - "" => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), - null => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), - _ => throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_NOT_SUPPORTED) - }; - - var parser = _provider.GetKeyedService(parserName); - var data = Cryptography.Base64.Decrypt(input.Data.Data); - var command = new ConfigurationCreateCommand(input.AppId, input.Environment) - { - Data = parser.Parse(data) - }; - return _bus.SendAsync(command, cancellationToken) + var command = new ConfigurationCreateCommand(input.TeamId); + + command = TypeAdapter.ProjectedAs(input.Data, command); + + return _bus.SendAsync(command, cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs index f0827c4..ec4ff99 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs @@ -7,19 +7,18 @@ namespace Nerosoft.Starfish.UseCases; /// /// 删除配置节点用例接口 /// -public interface IConfigurationDeleteUseCase : INonOutputUseCase; +internal interface IConfigurationDeleteUseCase : INonOutputUseCase; /// /// 删除配置节点输入 /// -/// -/// -public record ConfigurationDeleteInput(string AppId, string Environment) : IUseCaseInput; +/// +internal record ConfigurationDeleteInput(string Id) : IUseCaseInput; /// /// 删除配置节点用例 /// -public class ConfigurationDeleteUseCase : IConfigurationDeleteUseCase +internal class ConfigurationDeleteUseCase : IConfigurationDeleteUseCase { private readonly IBus _bus; @@ -30,7 +29,7 @@ public ConfigurationDeleteUseCase(IBus bus) public Task ExecuteAsync(ConfigurationDeleteInput input, CancellationToken cancellationToken = default) { - var command = new ConfigurationDeleteCommand(input.AppId, input.Environment); + var command = new ConfigurationDeleteCommand(input.Id); return _bus.SendAsync(command, cancellationToken); } } \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationDisableUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationDisableUseCase.cs new file mode 100644 index 0000000..181df76 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationDisableUseCase.cs @@ -0,0 +1,25 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Bus; +using Nerosoft.Starfish.Application; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationDisableUseCase : INonOutputUseCase; + +internal record ConfigurationDisableInput(string Id) : IUseCaseInput; + +internal class ConfigurationDisableUseCase : IConfigurationDisableUseCase +{ + private readonly IBus _bus; + + public ConfigurationDisableUseCase(IBus bus) + { + _bus = bus; + } + + public Task ExecuteAsync(ConfigurationDisableInput input, CancellationToken cancellationToken = default) + { + var command = new ConfigurationDisableCommand(input.Id); + return _bus.SendAsync(command, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationEnableUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationEnableUseCase.cs new file mode 100644 index 0000000..aff42db --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationEnableUseCase.cs @@ -0,0 +1,25 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Bus; +using Nerosoft.Starfish.Application; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationEnableUseCase : INonOutputUseCase; + +internal record ConfigurationEnableInput(string Id) : IUseCaseInput; + +internal class ConfigurationEnableUseCase : IConfigurationEnableUseCase +{ + private readonly IBus _bus; + + public ConfigurationEnableUseCase(IBus bus) + { + _bus = bus; + } + + public Task ExecuteAsync(ConfigurationEnableInput input, CancellationToken cancellationToken = default) + { + var command = new ConfigurationEnableCommand(input.Id); + return _bus.SendAsync(command, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs new file mode 100644 index 0000000..24f0492 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs @@ -0,0 +1,45 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Bus; +using Nerosoft.Starfish.Application; +using Nerosoft.Starfish.Transit; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationItemsUpdateUseCase : INonOutputUseCase; + +internal record ConfigurationItemsUpdateInput(string Id, ConfigurationItemsUpdateDto Data); + +internal class ConfigurationItemsUpdateUseCase : IConfigurationItemsUpdateUseCase +{ + private readonly IBus _bus; + private readonly IServiceProvider _provider; + + public ConfigurationItemsUpdateUseCase(IBus bus, IServiceProvider provider) + { + _bus = bus; + _provider = provider; + } + + public Task ExecuteAsync(ConfigurationItemsUpdateInput input, CancellationToken cancellationToken = default) + { + var format = input.Data.Type?.Normalize(TextCaseType.Lower).Trim(TextTrimType.All); + var parserName = format switch + { + Constants.Configuration.FormatText => "text", + Constants.Configuration.FormatJson => "json", + "" => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), + null => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), + _ => throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_NOT_SUPPORTED) + }; + + var parser = _provider.GetKeyedService(parserName); + var data = Cryptography.Base64.Decrypt(input.Data.Data); + var command = new ConfigurationItemsUpdateCommand(input.Id, input.Data.Mode, parser.Parse(data)); + + return _bus.SendAsync(command, cancellationToken) + .ContinueWith(task => + { + task.WaitAndUnwrapException(cancellationToken); + }, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs index d107542..6ca5527 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs @@ -8,20 +8,19 @@ namespace Nerosoft.Starfish.UseCases; /// /// 配置节点发布用例接口 /// -public interface IConfigurationPublishUseCase : INonOutputUseCase; +internal interface IConfigurationPublishUseCase : INonOutputUseCase; /// /// 配置节点发布输入 /// -/// -/// +/// /// -public record ConfigurationPublishInput(string AppId, string Environment, ConfigurationPublishDto Data) : IUseCaseInput; +internal record ConfigurationPublishInput(string Id, ConfigurationPublishRequestDto Data) : IUseCaseInput; /// /// 配置节点发布用例 /// -public class ConfigurationPublishUseCase : IConfigurationPublishUseCase +internal class ConfigurationPublishUseCase : IConfigurationPublishUseCase { private readonly IBus _bus; @@ -32,14 +31,7 @@ public ConfigurationPublishUseCase(IBus bus) public async Task ExecuteAsync(ConfigurationPublishInput input, CancellationToken cancellationToken = default) { - var command = new ConfigurationPublishCommand(input.AppId, input.Environment); + var command = new ConfigurationPublishCommand(input.Id, input.Data.Version, input.Data.Comment); await _bus.SendAsync(command, cancellationToken); - - var @event = new ConfigurationPublishedEvent(input.AppId, input.Environment) - { - Version = input.Data.Version, - Comment = input.Data.Comment - }; - await _bus.PublishAsync(@event, cancellationToken); } } \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs new file mode 100644 index 0000000..91d0532 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs @@ -0,0 +1,69 @@ +using System.Text.Json; +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Claims; +using Nerosoft.Starfish.Domain; +using Nerosoft.Starfish.Transit; +using StackExchange.Redis; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationPushRedisUseCase : INonOutputUseCase; + +internal record ConfigurationPushRedisInput(string Id, ConfigurationPushRedisRequestDto Data) : IUseCaseInput; + +internal sealed class ConfigurationPushRedisUseCase : IConfigurationPushRedisUseCase +{ + private readonly IConfigurationRepository _configurationRepository; + private readonly ITeamRepository _teamRepository; + private readonly UserPrincipal _identity; + + public ConfigurationPushRedisUseCase(IConfigurationRepository configurationRepository, ITeamRepository teamRepository, UserPrincipal identity) + { + _configurationRepository = configurationRepository; + _teamRepository = teamRepository; + _identity = identity; + } + + public async Task ExecuteAsync(ConfigurationPushRedisInput input, CancellationToken cancellationToken = default) + { + var permission = await _teamRepository.CheckPermissionAsync(input.Id, _identity.UserId, cancellationToken); + + if (permission != PermissionState.Edit) + { + throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); + } + + var configuration = await _configurationRepository.GetAsync(input.Id, false, [nameof(Configuration.Archive)], cancellationToken); + + if (configuration == null) + { + throw new ConfigurationNotFoundException(input.Id); + } + + if (configuration.Archive == null) + { + throw new NotFoundException("Archive not found."); + } + + if (string.IsNullOrWhiteSpace(configuration.Archive.Data)) + { + throw new InvalidDataException(); + } + + var data = GzipHelper.DecompressFromBase64(configuration.Archive.Data); + + var items = JsonSerializer.Deserialize>(data); + + var connection = await ConnectionMultiplexer.ConnectAsync(input.Data.ConnectionString); + using (connection) + { + var entries = items.Select(t => new HashEntry(t.Key, t.Value)).ToArray(); + + var database = connection.GetDatabase(input.Data.Database); + + await database.HashSetAsync(input.Data.Key, entries); + await database.KeyExpireAsync(input.Data.Key, default(TimeSpan?)); + await connection.CloseAsync(); + } + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs new file mode 100644 index 0000000..47edf02 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs @@ -0,0 +1,33 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Starfish.Domain; +using Nerosoft.Starfish.Repository; +using Nerosoft.Starfish.Transit; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationQueryUseCase : IUseCase, ConfigurationQueryOutput>; + +internal record ConfigurationQueryOutput(List Result) : IUseCaseOutput; + +internal class ConfigurationQueryUseCase : IConfigurationQueryUseCase +{ + private readonly IConfigurationRepository _repository; + + public ConfigurationQueryUseCase(IConfigurationRepository repository) + { + _repository = repository; + } + + public Task ExecuteAsync(GenericQueryInput input, CancellationToken cancellationToken = default) + { + var specification = input.Criteria.GetSpecification(); + var predicate = specification.Satisfy(); + return _repository.FindAsync(predicate, input.Skip, input.Count, cancellationToken) + .ContinueWith(task => + { + task.WaitAndUnwrapException(cancellationToken); + var result = task.Result.ProjectedAsCollection(); + return new ConfigurationQueryOutput(result); + }, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs index 7f6fa26..efb1fd3 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs @@ -1,43 +1,30 @@ using Nerosoft.Euonia.Application; using Nerosoft.Euonia.Bus; +using Nerosoft.Euonia.Mapping; using Nerosoft.Starfish.Application; using Nerosoft.Starfish.Transit; namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationUpdateUseCase : INonOutputUseCase; +internal interface IConfigurationUpdateUseCase : INonOutputUseCase; -public record ConfigurationUpdateInput(string AppId, string Environment, string Format, ConfigurationEditDto Data); +internal record ConfigurationUpdateInput(string Id, ConfigurationEditDto Data); -public class ConfigurationUpdateUseCase : IConfigurationUpdateUseCase +internal class ConfigurationUpdateUseCase : IConfigurationUpdateUseCase { private readonly IBus _bus; - private readonly IServiceProvider _provider; - public ConfigurationUpdateUseCase(IBus bus, IServiceProvider provider) + public ConfigurationUpdateUseCase(IBus bus) { _bus = bus; - _provider = provider; } public Task ExecuteAsync(ConfigurationUpdateInput input, CancellationToken cancellationToken = default) { - var format = input.Format?.Normalize(TextCaseType.Lower).Trim(TextTrimType.All); - var parserName = format switch - { - "plain/text" => "text", - "plain/json" => "json", - "" => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), - null => throw new ArgumentNullException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_REQUIRED), - _ => throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DATA_FORMAT_NOT_SUPPORTED) - }; - - var parser = _provider.GetKeyedService(parserName); - var data = Cryptography.Base64.Decrypt(input.Data.Data); - var command = new ConfigurationUpdateCommand(input.AppId, input.Environment) - { - Data = parser.Parse(data) - }; + var command = new ConfigurationUpdateCommand(input.Id); + + command = TypeAdapter.ProjectedAs(input.Data, command); + return _bus.SendAsync(command, cancellationToken) .ContinueWith(task => { diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs index bd84ee1..e01ece3 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationValueUpdateUseCase : INonOutputUseCase; +internal interface IConfigurationValueUpdateUseCase : INonOutputUseCase; -public record ConfigurationValueUpdateInput(string AppId, string Environment, string Key, string Value) : IUseCaseInput; +internal record ConfigurationValueUpdateInput(string Id, string Key, string Value) : IUseCaseInput; -public class ConfigurationValueUpdateUseCase : IConfigurationValueUpdateUseCase +internal class ConfigurationValueUpdateUseCase : IConfigurationValueUpdateUseCase { private readonly IBus _bus; @@ -19,7 +19,7 @@ public ConfigurationValueUpdateUseCase(IBus bus) public Task ExecuteAsync(ConfigurationValueUpdateInput input, CancellationToken cancellationToken = default) { - var command = new ConfigurationValueUpdateCommand(input.AppId, input.Environment, input.Key, input.Value); + var command = new ConfigurationValueUpdateCommand(input.Id, input.Key, input.Value); return _bus.SendAsync(command, cancellationToken) .ContinueWith(task => { diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs new file mode 100644 index 0000000..f5698e2 --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs @@ -0,0 +1,35 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Starfish.Domain; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IGetConfigurationArchiveUseCase : IUseCase; + +internal record GetConfigurationArchiveOutput(string Result) : IUseCaseOutput; + +internal record GetConfigurationArchiveInput(string Id) : IUseCaseInput; + +internal class GetConfigurationArchiveUseCase : IGetConfigurationArchiveUseCase +{ + private readonly IConfigurationRepository _repository; + + public GetConfigurationArchiveUseCase(IConfigurationRepository repository) + { + _repository = repository; + } + + public Task ExecuteAsync(GetConfigurationArchiveInput input, CancellationToken cancellationToken = default) + { + return _repository.GetAsync(input.Id, false, [nameof(Configuration.Archive)], cancellationToken) + .ContinueWith(task => + { + task.WaitAndUnwrapException(cancellationToken); + if (task.Result == null) + { + throw new NotFoundException("配置不存在"); + } + + return new GetConfigurationArchiveOutput(task.Result.Archive?.Data); + }, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs index ee64513..23ba1f4 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs @@ -10,24 +10,24 @@ namespace Nerosoft.Starfish.UseCases; /// /// 获取配置节点详情用例接口 /// -public interface IGetConfigurationDetailUseCase : IUseCase; +internal interface IGetConfigurationDetailUseCase : IUseCase; /// /// 获取配置节点详情用例输出 /// /// -public record GetConfigurationDetailOutput(ConfigurationDetailDto Result) : IUseCaseOutput; +internal record GetConfigurationDetailOutput(ConfigurationDto Result) : IUseCaseOutput; /// /// 获取配置节点详情用例输入 /// -/// -public record GetConfigurationDetailInput(string AppId, string Environment) : IUseCaseInput; +/// +internal record GetConfigurationDetailInput(string Id) : IUseCaseInput; /// /// 获取配置节点详情用例 /// -public class GetConfigurationDetailUseCase : IGetConfigurationDetailUseCase +internal class GetConfigurationDetailUseCase : IGetConfigurationDetailUseCase { private readonly IConfigurationRepository _repository; @@ -43,19 +43,11 @@ public GetConfigurationDetailUseCase(IConfigurationRepository repository) /// public Task ExecuteAsync(GetConfigurationDetailInput input, CancellationToken cancellationToken = default) { - ISpecification[] specifications = - [ - ConfigurationSpecification.AppIdEquals(input.AppId), - ConfigurationSpecification.EnvironmentEquals(input.Environment) - ]; - - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); - - return _repository.GetAsync(predicate, false, [nameof(Configuration.App)], cancellationToken) + return _repository.GetAsync(input.Id, false, [], cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); - var result = TypeAdapter.ProjectedAs(task.Result); + var result = TypeAdapter.ProjectedAs(task.Result); return new GetConfigurationDetailOutput(result); }, cancellationToken); } diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs index b2ed958..5abb5c5 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs @@ -6,25 +6,25 @@ namespace Nerosoft.Starfish.UseCases; /// /// 获取符合条件的配置数量用例接口 /// -public interface IGetConfigurationItemCountUseCase : IUseCase; +internal interface IGetConfigurationItemCountUseCase : IUseCase; /// /// 获取符合条件的配置数量用例输出 /// /// -public record GetConfigurationItemCountOutput(int Result) : IUseCaseOutput; +internal record GetConfigurationItemCountOutput(int Result) : IUseCaseOutput; /// /// 获取符合条件的配置数量用例输入 /// -/// -/// -public record GetConfigurationItemCountInput(string AppId, string Environment) : IUseCaseInput; +/// +/// +internal record GetConfigurationItemCountInput(string Id, string Key) : IUseCaseInput; /// /// 获取符合条件的配置数量用例 /// -public class GetConfigurationItemCountUseCase : IGetConfigurationItemCountUseCase +internal class GetConfigurationItemCountUseCase : IGetConfigurationItemCountUseCase { private readonly IConfigurationRepository _repository; @@ -40,7 +40,7 @@ public GetConfigurationItemCountUseCase(IConfigurationRepository repository) /// public Task ExecuteAsync(GetConfigurationItemCountInput input, CancellationToken cancellationToken = default) { - return _repository.GetItemCountAsync(input.AppId, input.Environment, cancellationToken) + return _repository.GetItemCountAsync(input.Id, input.Key, cancellationToken) .ContinueWith(t => new GetConfigurationItemCountOutput(t.Result), cancellationToken); } } \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs index 063008f..d8f2eef 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs @@ -9,27 +9,27 @@ namespace Nerosoft.Starfish.UseCases; /// /// 获取符合条件的配置列表用例接口 /// -public interface IGetConfigurationItemListUseCase : IUseCase; +internal interface IGetConfigurationItemListUseCase : IUseCase; /// /// 获取符合条件的配置列表用例输出 /// /// -public record GetConfigurationItemListOutput(List Result) : IUseCaseOutput; +internal record GetConfigurationItemListOutput(List Result) : IUseCaseOutput; /// /// 获取符合条件的配置列表用例输入 /// /// -/// +/// /// /// -public record GetConfigurationItemListInput(string Id, string Environment, int Skip, int Count) : IUseCaseInput; +internal record GetConfigurationItemListInput(string Id, string Key, int Skip, int Count) : IUseCaseInput; /// /// 获取符合条件的配置列表用例 /// -public class GetConfigurationItemListUseCase : IGetConfigurationItemListUseCase +internal class GetConfigurationItemListUseCase : IGetConfigurationItemListUseCase { private readonly IConfigurationRepository _repository; private readonly UserPrincipal _identity; @@ -63,7 +63,7 @@ public Task ExecuteAsync(GetConfigurationItemLis throw new AuthenticationException(); } - return _repository.GetItemListAsync(input.Id, input.Environment, input.Skip, input.Count, cancellationToken) + return _repository.GetItemListAsync(input.Id, input.Key, input.Skip, input.Count, cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationRawUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationRawUseCase.cs deleted file mode 100644 index da218f3..0000000 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationRawUseCase.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Nerosoft.Euonia.Application; -using Nerosoft.Starfish.Domain; - -namespace Nerosoft.Starfish.UseCases; - -public interface IGetConfigurationRawUseCase : IUseCase; - -public record GetConfigurationRawUseCaseOutput(string Result) : IUseCaseOutput; - -public record GetConfigurationRawInput(string AppId, string Environment) : IUseCaseInput; - -public class GetConfigurationRawUseCase : IGetConfigurationRawUseCase -{ - private readonly IConfigurationArchiveRepository _repository; - - public GetConfigurationRawUseCase(IConfigurationArchiveRepository repository) - { - _repository = repository; - } - - public Task ExecuteAsync(GetConfigurationRawInput input, CancellationToken cancellationToken = default) - { - return _repository.GetAsync(input.AppId, input.Environment, cancellationToken) - .ContinueWith(t => new GetConfigurationRawUseCaseOutput(t.Result.Data), cancellationToken); - } -} diff --git a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs b/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs deleted file mode 100644 index 555c7a3..0000000 --- a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Text.Json; -using Nerosoft.Euonia.Application; -using Nerosoft.Euonia.Claims; -using Nerosoft.Starfish.Domain; -using Nerosoft.Starfish.Transit; -using StackExchange.Redis; - -namespace Nerosoft.Starfish.UseCases; - -internal interface IPushRedisUseCase : INonOutputUseCase; - -internal record PushRedisInput(string AppId, string Environment, PushRedisRequestDto Data) : IUseCaseInput; - -internal sealed class PushRedisUseCase : IPushRedisUseCase -{ - private readonly IConfigurationArchiveRepository _configurationRepository; - private readonly IAppInfoRepository _appInfoRepository; - private readonly UserPrincipal _identity; - - public PushRedisUseCase(IConfigurationArchiveRepository configurationRepository, IAppInfoRepository appInfoRepository, UserPrincipal identity) - { - _configurationRepository = configurationRepository; - _appInfoRepository = appInfoRepository; - _identity = identity; - } - - public async Task ExecuteAsync(PushRedisInput input, CancellationToken cancellationToken = default) - { - var permission = await _appInfoRepository.CheckPermissionAsync(input.AppId, _identity.UserId, cancellationToken); - - if (!permission.IsIn(1, 2)) - { - throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); - } - - var archive = await _configurationRepository.GetAsync(input.AppId, input.Environment, cancellationToken); - - if (archive == null) - { - throw new ConfigurationNotFoundException(input.AppId, input.Environment); - } - - if (string.IsNullOrWhiteSpace(archive.Data)) - { - throw new InvalidDataException(); - } - - var data = GzipHelper.DecompressFromBase64(archive.Data); - - var items = JsonSerializer.Deserialize>(data); - - var connection = ConnectionMultiplexer.Connect(input.Data.ConnectionString); - using (connection) - { - var entries = items.Select(t => new HashEntry(t.Key, t.Value)).ToArray(); - - var database = connection.GetDatabase(input.Data.Database); - - await database.HashSetAsync(input.Data.Key, entries); - await database.KeyExpireAsync(input.Data.Key, default(TimeSpan?)); - await connection.CloseAsync(); - } - } -} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs b/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs new file mode 100644 index 0000000..1b3704b --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs @@ -0,0 +1,25 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Bus; +using Nerosoft.Starfish.Application; + +namespace Nerosoft.Starfish.UseCases; + +internal interface ISetConfigurationSecretUseCase : INonOutputUseCase; + +internal record SetConfigurationSecretInput(string Id, string Secret) : IUseCaseInput; + +internal class SetConfigurationSecretUseCase : ISetConfigurationSecretUseCase +{ + private readonly IBus _bus; + + public SetConfigurationSecretUseCase(IBus bus) + { + _bus = bus; + } + + public Task ExecuteAsync(SetConfigurationSecretInput input, CancellationToken cancellationToken = default) + { + var command = new ConfigurationSetSecretCommand(input.Id, input.Secret); + return _bus.SendAsync(command, cancellationToken); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/UseCases/Identity/ChangePasswordUseCase.cs b/Source/Starfish.Service/UseCases/Identity/ChangePasswordUseCase.cs index 0b7767d..8bd518b 100644 --- a/Source/Starfish.Service/UseCases/Identity/ChangePasswordUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/ChangePasswordUseCase.cs @@ -7,11 +7,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IChangePasswordUseCase : INonOutputUseCase; +internal interface IChangePasswordUseCase : INonOutputUseCase; -public record ChangePasswordInput(string OldPassword, string NewPassword) : IUseCaseInput; +internal record ChangePasswordInput(string OldPassword, string NewPassword) : IUseCaseInput; -public class ChangePasswordUseCase : IChangePasswordUseCase +internal class ChangePasswordUseCase : IChangePasswordUseCase { private readonly IUserRepository _repository; private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs b/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs index fbb4432..4abf7ba 100644 --- a/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs @@ -10,35 +10,22 @@ namespace Nerosoft.Starfish.UseCases; /// /// 密码登录用例接口 /// -public interface IGrantWithPasswordUseCase : IUseCase; +internal interface IGrantWithPasswordUseCase : IUseCase; /// /// 密码登录输入参数 /// -public class GrantWithPasswordUseCaseInput : IUseCaseInput -{ - /// - /// 用户名 - /// - public string UserName { get; init; } - - /// - /// 密码 - /// - public string Password { get; init; } -} +internal record GrantWithPasswordUseCaseInput(string UserName, string Password) : IUseCaseInput; /// /// 密码登录输出参数 /// -public class GrantWithPasswordUseCaseOutput : IdentityUseCaseOutput -{ -} +internal record GrantWithPasswordUseCaseOutput : IdentityUseCaseOutput; /// /// 密码登录用例 /// -public class GrantWithPasswordUseCase : IGrantWithPasswordUseCase +internal class GrantWithPasswordUseCase : IGrantWithPasswordUseCase { private readonly IServiceProvider _provider; diff --git a/Source/Starfish.Service/UseCases/Identity/GrantWithRefreshTokenUseCase.cs b/Source/Starfish.Service/UseCases/Identity/GrantWithRefreshTokenUseCase.cs index 9778335..c415c38 100644 --- a/Source/Starfish.Service/UseCases/Identity/GrantWithRefreshTokenUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/GrantWithRefreshTokenUseCase.cs @@ -12,30 +12,22 @@ namespace Nerosoft.Starfish.UseCases; /// /// 刷新令牌用例接口 /// -public interface IGrantWithRefreshTokenUseCase : IUseCase; +internal interface IGrantWithRefreshTokenUseCase : IUseCase; /// /// 刷新令牌输入参数 /// -public class GrantWithRefreshTokenUseCaseInput : IUseCaseInput -{ - /// - /// 刷新令牌 - /// - public string Token { get; set; } -} +internal record GrantWithRefreshTokenUseCaseInput(string Token) : IUseCaseInput; /// /// 刷新令牌输出 /// -public class GrantWithRefreshTokenUseCaseOutput : IdentityUseCaseOutput -{ -} +internal record GrantWithRefreshTokenUseCaseOutput : IdentityUseCaseOutput; /// /// 刷新令牌用例 /// -public class GrantWithRefreshTokenUseCase : IGrantWithRefreshTokenUseCase +internal class GrantWithRefreshTokenUseCase : IGrantWithRefreshTokenUseCase { private readonly IServiceProvider _provider; diff --git a/Source/Starfish.Service/UseCases/Identity/IdentityCommonComponent.cs b/Source/Starfish.Service/UseCases/Identity/IdentityCommonComponent.cs index 7b73e01..b826ae2 100644 --- a/Source/Starfish.Service/UseCases/Identity/IdentityCommonComponent.cs +++ b/Source/Starfish.Service/UseCases/Identity/IdentityCommonComponent.cs @@ -6,7 +6,7 @@ namespace Nerosoft.Starfish.UseCases; /// /// 用户认证公共组件 /// -public class IdentityCommonComponent +internal class IdentityCommonComponent { private readonly IConfiguration _configuration; diff --git a/Source/Starfish.Service/UseCases/Identity/IdentityUseCaseOutput.cs b/Source/Starfish.Service/UseCases/Identity/IdentityUseCaseOutput.cs index 4d3d908..4226a1c 100644 --- a/Source/Starfish.Service/UseCases/Identity/IdentityUseCaseOutput.cs +++ b/Source/Starfish.Service/UseCases/Identity/IdentityUseCaseOutput.cs @@ -5,7 +5,7 @@ namespace Nerosoft.Starfish.UseCases; /// /// 身份验证用例输出 /// -public abstract class IdentityUseCaseOutput : IUseCaseOutput +public abstract record IdentityUseCaseOutput : IUseCaseOutput { /// /// 访问令牌 diff --git a/Source/Starfish.Service/UseCases/Identity/ResetPasswordUseCase.cs b/Source/Starfish.Service/UseCases/Identity/ResetPasswordUseCase.cs index 0d42989..1240a2f 100644 --- a/Source/Starfish.Service/UseCases/Identity/ResetPasswordUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/ResetPasswordUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IResetPasswordUseCase : INonOutputUseCase; +internal interface IResetPasswordUseCase : INonOutputUseCase; -public record ResetPasswordInput(string Id, string Password) : IUseCaseInput; +internal record ResetPasswordInput(string Id, string Password) : IUseCaseInput; -public class ResetPasswordUseCase : IResetPasswordUseCase +internal class ResetPasswordUseCase : IResetPasswordUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Identity/UserCountUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserCountUseCase.cs index cc9ba11..0a9e00a 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserCountUseCase.cs @@ -5,9 +5,9 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserCountUseCase : IUseCase; +internal interface IUserCountUseCase : IUseCase; -public class UserCountUseCase : IUserCountUseCase +internal class UserCountUseCase : IUserCountUseCase { private readonly IUserRepository _repository; diff --git a/Source/Starfish.Service/UseCases/Identity/UserCreateUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserCreateUseCase.cs index b18390c..07657dd 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserCreateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserCreateUseCase.cs @@ -5,13 +5,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserCreateUseCase : IUseCase; +internal interface IUserCreateUseCase : IUseCase; -public record UserCreateOutput(string Result) : IUseCaseOutput; +internal record UserCreateOutput(string Result) : IUseCaseOutput; -public record UserCreateInput(UserCreateDto Data) : IUseCaseInput; +internal record UserCreateInput(UserCreateDto Data) : IUseCaseInput; -public class UserCreateUseCase : IUserCreateUseCase +internal class UserCreateUseCase : IUserCreateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Identity/UserDeleteUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserDeleteUseCase.cs index d1d7372..23b3459 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserDeleteUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserDeleteUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserDeleteUseCase : INonOutputUseCase; +internal interface IUserDeleteUseCase : INonOutputUseCase; -public record UserDeleteInput(string Id) : IUseCaseInput; +internal record UserDeleteInput(string Id) : IUseCaseInput; -public class UserDeleteUseCase : IUserDeleteUseCase +internal class UserDeleteUseCase : IUserDeleteUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Identity/UserDetailUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserDetailUseCase.cs index 4a15054..8b107a8 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserDetailUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserDetailUseCase.cs @@ -6,13 +6,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserDetailUseCase : IUseCase; +internal interface IUserDetailUseCase : IUseCase; -public record UserDetailOutput(UserDetailDto Result) : IUseCaseOutput; +internal record UserDetailOutput(UserDetailDto Result) : IUseCaseOutput; -public record UserDetailInput(string Id) : IUseCaseInput; +internal record UserDetailInput(string Id) : IUseCaseInput; -public class UserDetailUseCase : IUserDetailUseCase +internal class UserDetailUseCase : IUserDetailUseCase { private readonly IUserRepository _repository; diff --git a/Source/Starfish.Service/UseCases/Identity/UserQueryUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserQueryUseCase.cs index 4c3252f..520da4a 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserQueryUseCase.cs @@ -7,13 +7,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserQueryUseCase : IUseCase; +internal interface IUserQueryUseCase : IUseCase, UserSearchOutput>; -public record UserSearchOutput(List Result) : IUseCaseOutput; +internal record UserSearchOutput(List Result) : IUseCaseOutput; -public record UserSearchInput(UserCriteria Criteria, int Skip, int Count) : IUseCaseInput; - -public class UserQueryUseCase : IUserQueryUseCase +internal class UserQueryUseCase : IUserQueryUseCase { private readonly IUserRepository _repository; private readonly UserPrincipal _identity; @@ -24,18 +22,8 @@ public UserQueryUseCase(IUserRepository repository, UserPrincipal identity) _identity = identity; } - public Task ExecuteAsync(UserSearchInput input, CancellationToken cancellationToken = default) + public Task ExecuteAsync(GenericQueryInput input, CancellationToken cancellationToken = default) { - if (input.Skip < 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_SKIP_CANNOT_BE_NEGATIVE); - } - - if (input.Count <= 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_COUNT_MUST_GREATER_THAN_0); - } - if (!_identity.IsAuthenticated) { throw new AuthenticationException(); diff --git a/Source/Starfish.Service/UseCases/Identity/UserUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Identity/UserUpdateUseCase.cs index 6d095aa..2c2c73e 100644 --- a/Source/Starfish.Service/UseCases/Identity/UserUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/UserUpdateUseCase.cs @@ -5,11 +5,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IUserUpdateUseCase : INonOutputUseCase; +internal interface IUserUpdateUseCase : INonOutputUseCase; -public record UserUpdateInput(string Id, UserUpdateDto Data) : IUseCaseInput; +internal record UserUpdateInput(string Id, UserUpdateDto Data) : IUseCaseInput; -public class UserUpdateUseCase : IUserUpdateUseCase +internal class UserUpdateUseCase : IUserUpdateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Logging/LogsCountUseCase.cs b/Source/Starfish.Service/UseCases/Logging/LogsCountUseCase.cs index 51f1475..9481c9c 100644 --- a/Source/Starfish.Service/UseCases/Logging/LogsCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Logging/LogsCountUseCase.cs @@ -9,24 +9,24 @@ namespace Nerosoft.Starfish.UseCases; /// /// 日志数量查询用例接口 /// -public interface ILogsCountUseCase : IUseCase; +internal interface ILogsCountUseCase : IUseCase; /// /// 日志数量查询用例输入 /// /// -public record LogsCountUseCaseInput(OperateLogCriteria Criteria) : IUseCaseInput; +internal record LogsCountUseCaseInput(OperateLogCriteria Criteria) : IUseCaseInput; /// /// 日志数量查询用例输出 /// /// -public record LogsCountUseCaseOutput(int Count) : IUseCaseOutput; +internal record LogsCountUseCaseOutput(int Count) : IUseCaseOutput; /// /// 日志数量查询用例 /// -public class LogsCountUseCase : ILogsCountUseCase +internal class LogsCountUseCase : ILogsCountUseCase { private readonly IOperateLogRepository _repository; private readonly UserPrincipal _user; diff --git a/Source/Starfish.Service/UseCases/Logging/LogsQueryUseCase.cs b/Source/Starfish.Service/UseCases/Logging/LogsQueryUseCase.cs index d0020c5..1b5383f 100644 --- a/Source/Starfish.Service/UseCases/Logging/LogsQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Logging/LogsQueryUseCase.cs @@ -10,28 +10,18 @@ namespace Nerosoft.Starfish.UseCases; /// /// 日志搜索用例 /// -public interface ILogsQueryUseCase : IUseCase -{ -} - -/// -/// 日志搜索用例输入 -/// -/// -/// -/// -public record LogsQueryUseCaseInput(OperateLogCriteria Criteria, int Skip, int Count) : IUseCaseInput; +internal interface ILogsQueryUseCase : IUseCase, LogsQueryUseCaseOutput>; /// /// 日志搜索用例输出 /// /// -public record LogsQueryUseCaseOutput(List Logs) : IUseCaseOutput; +internal record LogsQueryUseCaseOutput(List Logs) : IUseCaseOutput; /// /// 日志搜索用例 /// -public class LogsQueryUseCase : ILogsQueryUseCase +internal class LogsQueryUseCase : ILogsQueryUseCase { private readonly IOperateLogRepository _repository; private readonly UserPrincipal _identity; @@ -48,18 +38,8 @@ public LogsQueryUseCase(IOperateLogRepository repository, UserPrincipal identity } /// - public async Task ExecuteAsync(LogsQueryUseCaseInput input, CancellationToken cancellationToken = default) + public async Task ExecuteAsync(GenericQueryInput input, CancellationToken cancellationToken = default) { - if (input.Skip < 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_SKIP_CANNOT_BE_NEGATIVE); - } - - if (input.Count <= 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_COUNT_MUST_GREATER_THAN_0); - } - if (!_identity.IsAuthenticated) { throw new AuthenticationException(); diff --git a/Source/Starfish.Service/UseCases/Team/TeamCountUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamCountUseCase.cs index 8683708..a9067bd 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamCountUseCase.cs @@ -7,13 +7,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamCountUseCase : IUseCase; +internal interface ITeamCountUseCase : IUseCase; -public record TeamCountInput(TeamCriteria Criteria) : IUseCaseInput; +internal record TeamCountInput(TeamCriteria Criteria) : IUseCaseInput; -public record TeamCountOutput(int Result) : IUseCaseOutput; +internal record TeamCountOutput(int Result) : IUseCaseOutput; -public class TeamCountUseCase : ITeamCountUseCase +internal class TeamCountUseCase : ITeamCountUseCase { private readonly ITeamRepository _repository; private readonly UserPrincipal _identity; diff --git a/Source/Starfish.Service/UseCases/Team/TeamCreateUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamCreateUseCase.cs index 7f3420c..a6f9e36 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamCreateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamCreateUseCase.cs @@ -5,13 +5,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamCreateUseCase : IUseCase; +internal interface ITeamCreateUseCase : IUseCase; -public record TeamCreateInput(TeamEditDto Data) : IUseCaseInput; +internal record TeamCreateInput(TeamEditDto Data) : IUseCaseInput; -public record TeamCreateOutput(string Result) : IUseCaseOutput; +internal record TeamCreateOutput(string Result) : IUseCaseOutput; -public class TeamCreateUseCase : ITeamCreateUseCase +internal class TeamCreateUseCase : ITeamCreateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Team/TeamDetailUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamDetailUseCase.cs index bb7de0c..835c48c 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamDetailUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamDetailUseCase.cs @@ -8,13 +8,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamDetailUseCase : IUseCase; +internal interface ITeamDetailUseCase : IUseCase; -public record TeamDetailInput(string Id) : IUseCaseInput; +internal record TeamDetailInput(string Id) : IUseCaseInput; -public record TeamDetailOutput(TeamDetailDto Result) : IUseCaseOutput; +internal record TeamDetailOutput(TeamDetailDto Result) : IUseCaseOutput; -public class TeamDetailUseCase : ITeamDetailUseCase +internal class TeamDetailUseCase : ITeamDetailUseCase { private readonly ITeamRepository _repository; private readonly UserPrincipal _identity; diff --git a/Source/Starfish.Service/UseCases/Team/TeamMemberAppendUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamMemberAppendUseCase.cs index 1390a71..bfb9f04 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamMemberAppendUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamMemberAppendUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamMemberAppendUseCase : INonOutputUseCase; +internal interface ITeamMemberAppendUseCase : INonOutputUseCase; -public record TeamMemberAppendInput(string Id, List UserIds) : IUseCaseInput; +internal record TeamMemberAppendInput(string Id, List UserIds) : IUseCaseInput; -public class TeamMemberAppendUseCase : ITeamMemberAppendUseCase +internal class TeamMemberAppendUseCase : ITeamMemberAppendUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Team/TeamMemberQueryUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamMemberQueryUseCase.cs index fddef8d..6347f19 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamMemberQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamMemberQueryUseCase.cs @@ -4,13 +4,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamMemberQueryUseCase : IUseCase; +internal interface ITeamMemberQueryUseCase : IUseCase; -public record TeamMemberQueryOutput(List Result) : IUseCaseOutput; +internal record TeamMemberQueryOutput(List Result) : IUseCaseOutput; -public record TeamMemberQueryInput(string Id) : IUseCaseInput; +internal record TeamMemberQueryInput(string Id) : IUseCaseInput; -public class TeamMemberQueryUseCase : ITeamMemberQueryUseCase +internal class TeamMemberQueryUseCase : ITeamMemberQueryUseCase { private readonly ITeamRepository _repository; diff --git a/Source/Starfish.Service/UseCases/Team/TeamMemberQuitUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamMemberQuitUseCase.cs index 13ac00f..fab5883 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamMemberQuitUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamMemberQuitUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamMemberQuitUseCase : INonOutputUseCase; +internal interface ITeamMemberQuitUseCase : INonOutputUseCase; -public record TeamMemberQuitInput(string TeamId, string UserId) : IUseCaseInput; +internal record TeamMemberQuitInput(string TeamId, string UserId) : IUseCaseInput; -public class TeamMemberQuitUseCase : ITeamMemberQuitUseCase +internal class TeamMemberQuitUseCase : ITeamMemberQuitUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Team/TeamMemberRemoveUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamMemberRemoveUseCase.cs index 2aa8c72..2a83aab 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamMemberRemoveUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamMemberRemoveUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamMemberRemoveUseCase : INonOutputUseCase; +internal interface ITeamMemberRemoveUseCase : INonOutputUseCase; -public record TeamMemberRemoveInput(string Id, List UserIds) : IUseCaseInput; +internal record TeamMemberRemoveInput(string Id, List UserIds) : IUseCaseInput; -public class TeamMemberRemoveUseCase : ITeamMemberRemoveUseCase +internal class TeamMemberRemoveUseCase : ITeamMemberRemoveUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Team/TeamQueryUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamQueryUseCase.cs index db944a8..9d9de9f 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamQueryUseCase.cs @@ -7,13 +7,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamQueryUseCase : IUseCase; +internal interface ITeamQueryUseCase : IUseCase, TeamQueryOutput>; -public record TeamQueryInput(TeamCriteria Criteria, int Skip, int Count) : IUseCaseInput; +internal record TeamQueryOutput(List Result) : IUseCaseOutput; -public record TeamQueryOutput(List Result) : IUseCaseOutput; - -public class TeamQueryUseCase : ITeamQueryUseCase +internal class TeamQueryUseCase : ITeamQueryUseCase { private readonly ITeamRepository _repository; private readonly UserPrincipal _identity; @@ -24,18 +22,8 @@ public TeamQueryUseCase(ITeamRepository repository, UserPrincipal identity) _identity = identity; } - public Task ExecuteAsync(TeamQueryInput input, CancellationToken cancellationToken = default) + public Task ExecuteAsync(GenericQueryInput input, CancellationToken cancellationToken = default) { - if (input.Skip < 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_SKIP_CANNOT_BE_NEGATIVE); - } - - if (input.Count <= 0) - { - throw new BadRequestException(Resources.IDS_ERROR_PARAM_COUNT_MUST_GREATER_THAN_0); - } - if (!_identity.IsAuthenticated) { throw new AuthenticationException(); diff --git a/Source/Starfish.Service/UseCases/Team/TeamUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Team/TeamUpdateUseCase.cs index ed63e69..ef558f7 100644 --- a/Source/Starfish.Service/UseCases/Team/TeamUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Team/TeamUpdateUseCase.cs @@ -5,11 +5,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ITeamUpdateUseCase : INonOutputUseCase; +internal interface ITeamUpdateUseCase : INonOutputUseCase; -public record TeamUpdateInput(string Id, TeamEditDto Data) : IUseCaseInput; +internal record TeamUpdateInput(string Id, TeamEditDto Data) : IUseCaseInput; -public class TeamUpdateUseCase : ITeamUpdateUseCase +internal class TeamUpdateUseCase : ITeamUpdateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/UseCaseModule.cs b/Source/Starfish.Service/UseCases/UseCaseModule.cs index 74bc494..ab63d36 100644 --- a/Source/Starfish.Service/UseCases/UseCaseModule.cs +++ b/Source/Starfish.Service/UseCases/UseCaseModule.cs @@ -11,7 +11,7 @@ public class UseCaseModule : ModuleContextBase public override void ConfigureServices(ServiceConfigurationContext context) { var types = typeof(UseCaseModule).Assembly.GetTypes() - .Where(t => t.IsClass && t.IsPublic && t.Name.EndsWith("UseCase")); + .Where(t => t.IsClass && t.Name.EndsWith("UseCase")); foreach (var type in types) { diff --git a/Source/Starfish.Transit/Apps/AppInfoCreateDto.cs b/Source/Starfish.Transit/Apps/AppInfoCreateDto.cs deleted file mode 100644 index cc57775..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoCreateDto.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 应用创建请求Dto -/// -public class AppInfoCreateDto -{ - /// - /// 团队Id - /// - public string TeamId { get; set; } - - /// - /// 应用名称 - /// - public string Name { get; set; } = default!; - - /// - /// 应用代码 - /// - public string Code { get; set; } = default!; - - /// - /// 密钥 - /// - public string Secret { get; set; } - - /// - /// 应用描述 - /// - public string Description { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Transit/Apps/AppInfoCriteria.cs b/Source/Starfish.Transit/Apps/AppInfoCriteria.cs deleted file mode 100644 index 4957b29..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoCriteria.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 应用信息查询条件 -/// -public class AppInfoCriteria -{ - /// - /// 团队Id - /// - public string TeamId { get; set; } - - /// - /// 关键字 - /// - /// - /// 匹配应用名称、应用描述、应用标识 - /// - public string Keyword { get; set; } - - /// - /// 状态 - /// - /// - /// 0-全部 - /// 1-启用 - /// 2-禁用 - /// - public int Status { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Transit/Apps/AppInfoDetailDto.cs b/Source/Starfish.Transit/Apps/AppInfoDetailDto.cs deleted file mode 100644 index 0835872..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoDetailDto.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 应用详细信息Dto -/// -public class AppInfoDetailDto -{ - /// - /// Id - /// - public string Id { get; set; } - - /// - /// 团队Id - /// - public string TeamId { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 描述 - /// - public string Description { get; set; } - - /// - /// 状态 - /// - public string Status { get; set; } - - /// - /// 状态描述 - /// - public string StatusDescription { get; set; } - - /// - /// 创建时间 - /// - public DateTime CreateTime { get; set; } - - /// - /// 更新时间 - /// - public DateTime UpdateTime { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Transit/Apps/AppInfoItemDto.cs b/Source/Starfish.Transit/Apps/AppInfoItemDto.cs deleted file mode 100644 index 1df0304..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoItemDto.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 应用信息Dto -/// -/// 用于列表显示 -public class AppInfoItemDto -{ - /// - /// Id - /// - public string Id { get; set; } - - /// - /// 所属团队Id - /// - public string TeamId { get; set; } - - /// - /// 所属团队名称 - /// - public string TeamName { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 状态 - /// - public string Status { get; set; } - - /// - /// 状态描述 - /// - public string StatusDescription { get; set; } - - /// - /// 创建时间 - /// - public DateTime CreateTime { get; set; } - - /// - /// 更新时间 - /// - public DateTime UpdateTime { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Transit/Apps/AppInfoUpdateDto.cs b/Source/Starfish.Transit/Apps/AppInfoUpdateDto.cs deleted file mode 100644 index 82a2b28..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoUpdateDto.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 应用更新请求Dto -/// -public class AppInfoUpdateDto -{ - /// - /// 应用名称 - /// - public string Name { get; set; } - - /// - /// 应用描述 - /// - public string Description { get; set; } - - /// - /// 是否启用 - /// - public bool? IsEnabled { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Transit/Configs/ConfigurationCriteria.cs b/Source/Starfish.Transit/Configs/ConfigurationCriteria.cs index 44393d4..6db5a34 100644 --- a/Source/Starfish.Transit/Configs/ConfigurationCriteria.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationCriteria.cs @@ -11,12 +11,12 @@ public class ConfigurationCriteria public string TeamId { get; set; } /// - /// App唯一编码 + /// 关键字 /// - public string AppName { get; set; } + public string Keyword { get; set; } /// - /// 应用环境 + /// 状态 /// - public string Environment { get; set; } + public int Status { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Transit/Configs/ConfigurationDetailDto.cs b/Source/Starfish.Transit/Configs/ConfigurationDto.cs similarity index 62% rename from Source/Starfish.Transit/Configs/ConfigurationDetailDto.cs rename to Source/Starfish.Transit/Configs/ConfigurationDto.cs index 7d9c4ea..cb2d9b1 100644 --- a/Source/Starfish.Transit/Configs/ConfigurationDetailDto.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationDto.cs @@ -1,29 +1,34 @@ namespace Nerosoft.Starfish.Transit; /// -/// 配置详情Dto +/// 配置Dto /// -public class ConfigurationDetailDto +public class ConfigurationDto { /// /// Id /// - public long Id { get; set; } + public string Id { get; set; } /// - /// 应用Id + /// 团队Id /// - public string AppId { get; set; } + public string TeamId { get; set; } /// - /// 应用名称 + /// 团队名称 /// - public string AppName { get; set; } + public string TeamName { get; set; } /// - /// 应用环境 + /// 配置名称 /// - public string Environment { get; set; } + public string Name { get; set; } + + /// + /// 配置描述 + /// + public string Description { get; set; } /// /// 当前版本号 @@ -43,7 +48,7 @@ public class ConfigurationDetailDto /// /// 状态名称 /// - public string StatusDescription { get; set; } + public string StatusName { get; set; } /// /// 修改时间 diff --git a/Source/Starfish.Transit/Configs/ConfigurationEditDto.cs b/Source/Starfish.Transit/Configs/ConfigurationEditDto.cs index 946c939..687aaa8 100644 --- a/Source/Starfish.Transit/Configs/ConfigurationEditDto.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationEditDto.cs @@ -6,12 +6,20 @@ public class ConfigurationEditDto { /// - /// 数据类型 + /// 配置名称 /// - public string Type { get; set; } + /// + /// 同一个TeamId下的配置名称不能重复 + /// + public string Name { get; set; } /// - /// 配置内容 + /// 配置描述 /// - public string Data { get; set; } + public string Description { get; set; } + + /// + /// 访问密钥 + /// + public string Secret { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Transit/Configs/ConfigurationItemsUpdateDto.cs b/Source/Starfish.Transit/Configs/ConfigurationItemsUpdateDto.cs new file mode 100644 index 0000000..59a7270 --- /dev/null +++ b/Source/Starfish.Transit/Configs/ConfigurationItemsUpdateDto.cs @@ -0,0 +1,29 @@ +namespace Nerosoft.Starfish.Transit; + +/// +/// 配置项更新数据传输对象 +/// +public class ConfigurationItemsUpdateDto +{ + /// + /// 数据类型 + /// + public string Type { get; set; } + + /// + /// 更新方式 + /// + /// + /// diff-差异更新 + /// full-全量更新 + /// + public string Mode { get; set; } + + /// + /// 数据 + /// + /// + /// 使用Base64编码 + /// + public string Data { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Transit/Configs/ConfigurationPublishDto.cs b/Source/Starfish.Transit/Configs/ConfigurationPublishRequestDto.cs similarity index 85% rename from Source/Starfish.Transit/Configs/ConfigurationPublishDto.cs rename to Source/Starfish.Transit/Configs/ConfigurationPublishRequestDto.cs index d084813..578cb01 100644 --- a/Source/Starfish.Transit/Configs/ConfigurationPublishDto.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationPublishRequestDto.cs @@ -3,7 +3,7 @@ /// /// 配置节点发布Dto /// -public class ConfigurationPublishDto +public class ConfigurationPublishRequestDto { /// /// 版本号 diff --git a/Source/Starfish.Transit/Configs/PushRedisRequestDto.cs b/Source/Starfish.Transit/Configs/ConfigurationPushRedisRequestDto.cs similarity index 89% rename from Source/Starfish.Transit/Configs/PushRedisRequestDto.cs rename to Source/Starfish.Transit/Configs/ConfigurationPushRedisRequestDto.cs index c17fc3d..c14b409 100644 --- a/Source/Starfish.Transit/Configs/PushRedisRequestDto.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationPushRedisRequestDto.cs @@ -3,7 +3,7 @@ /// /// 同步配置到Redis请求Dto /// -public class PushRedisRequestDto +public class ConfigurationPushRedisRequestDto { /// /// Redis连接字符串 diff --git a/Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs b/Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs similarity index 60% rename from Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs rename to Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs index 9c0ac9c..2082c74 100644 --- a/Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs +++ b/Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs @@ -1,12 +1,12 @@ namespace Nerosoft.Starfish.Transit; /// -/// 设置应用密钥Dto +/// 访问密钥设置请求 /// -public class AppInfoSetSecretDto +public class ConfigurationSecretSetRequestDto { /// - /// 密钥 + /// 访问密钥 /// public string Secret { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Transit/Configs/ConfigurationValueUpdateDto.cs b/Source/Starfish.Transit/Configs/ConfigurationValueUpdateDto.cs deleted file mode 100644 index e071c13..0000000 --- a/Source/Starfish.Transit/Configs/ConfigurationValueUpdateDto.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 配置项更新Dto -/// -public class ConfigurationValueUpdateDto -{ - /// - /// - /// - public string Value { get; set; } -} \ No newline at end of file diff --git a/Source/Starfish.Webapi/Controllers/AppsController.cs b/Source/Starfish.Webapi/Controllers/AppsController.cs deleted file mode 100644 index a2823fc..0000000 --- a/Source/Starfish.Webapi/Controllers/AppsController.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Nerosoft.Starfish.Application; -using Nerosoft.Starfish.Transit; - -namespace Nerosoft.Starfish.Webapi.Controllers; - -/// -/// 应用管理接口 -/// -[Route("api/[controller]")] -[ApiController, ApiExplorerSettings(GroupName = "configuration")] -[Authorize] -public class AppsController : ControllerBase -{ - private readonly IAppsApplicationService _service; - - /// - /// 构造函数 - /// - /// - public AppsController(IAppsApplicationService service) - { - _service = service; - } - - /// - /// 搜索应用信息 - /// - /// - /// - /// - /// - [HttpGet] - [Produces>] - public async Task SearchAsync([FromQuery] AppInfoCriteria criteria, int skip = Constants.Query.Skip, int count = Constants.Query.Count) - { - var result = await _service.QueryAsync(criteria, skip, count, HttpContext.RequestAborted); - return Ok(result); - } - - /// - /// 查询应用数量 - /// - /// - /// - [HttpGet("count")] - [Produces] - public async Task CountAsync([FromQuery] AppInfoCriteria criteria) - { - var result = await _service.CountAsync(criteria, HttpContext.RequestAborted); - return Ok(result); - } - - /// - /// 获取应用详情 - /// - /// - /// - [HttpGet("{id}")] - [Produces] - public async Task GetAsync(string id) - { - var result = await _service.GetAsync(id, HttpContext.RequestAborted); - return Ok(result); - } - - /// - /// 创建应用 - /// - /// - /// - [HttpPost] - public async Task CreateAsync([FromBody] AppInfoCreateDto model) - { - var result = await _service.CreateAsync(model, HttpContext.RequestAborted); - //HttpContext.Response.Headers.Add("Location", $"/api/apps/{result}"); - HttpContext.Response.Headers.Append("Entry", result); - return Ok(result); - } - - /// - /// 更新应用 - /// - /// - /// - /// - [HttpPut("{id}")] - public async Task UpdateAsync(string id, [FromBody] AppInfoUpdateDto model) - { - await _service.UpdateAsync(id, model, HttpContext.RequestAborted); - return Ok(); - } - - /// - /// 启用应用 - /// - /// - /// - [HttpPut("{id}/enable")] - public async Task EnableAsync(string id) - { - await _service.EnableAsync(id, HttpContext.RequestAborted); - return Ok(); - } - - /// - /// 禁用应用 - /// - /// - /// - [HttpPut("{id}/disable")] - public async Task DisableAsync(string id) - { - await _service.DisableAsync(id, HttpContext.RequestAborted); - return Ok(); - } - - /// - /// 删除应用 - /// - /// - /// - [HttpDelete("{id}")] - public async Task DeleteAsync(string id) - { - await _service.DeleteAsync(id, HttpContext.RequestAborted); - return Ok(); - } - - /// - /// 设置应用密钥 - /// - /// - /// - /// - [HttpPut("{id}/secret")] - public async Task SetSecretAsync(string id, [FromBody] AppInfoSetSecretDto model) - { - await _service.SetSecretAsync(id, model.Secret, HttpContext.RequestAborted); - return Ok(); - } -} \ No newline at end of file diff --git a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index ab08c1f..54cfea5 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -9,7 +9,7 @@ namespace Nerosoft.Starfish.Webapi.Controllers; /// /// 应用配置管理接口 /// -[Route("api/apps/{id}/[controller]/{environment}")] +[Route("api/[controller]")] [ApiController, ApiExplorerSettings(GroupName = "configuration")] [Authorize] public class ConfigurationController : ControllerBase @@ -26,86 +26,56 @@ public ConfigurationController(IConfigurationApplicationService service) } /// - /// 获取配置项列表 + /// 查询配置列表 /// - /// 应用Id - /// 应用环境 + /// /// /// - /// /// - [HttpGet("item")] - [Produces(typeof(List))] - public async Task GetItemListAsync(string id, string environment, int skip = Constants.Query.Skip, int count = Constants.Query.Count, [FromHeader(Name = "x-format")] string format = null) + [HttpGet] + [Produces>] + public async Task QueryAsync([FromQuery] ConfigurationCriteria criteria, int skip = Constants.Query.Skip, int count = Constants.Query.Count) { - switch (format) - { - case Constants.Configuration.FormatText: - var text = await _service.GetItemsInTextAsync(id, environment, "text", HttpContext.RequestAborted); - return Ok(text); - case Constants.Configuration.FormatJson: - var json = await _service.GetItemsInTextAsync(id, environment, "json", HttpContext.RequestAborted); - return Ok(json); - default: - var result = await _service.GetItemListAsync(id, environment, skip, count, HttpContext.RequestAborted); - return Ok(result); - } + var result = await _service.QueryAsync(criteria, skip, count, HttpContext.RequestAborted); + return Ok(result); } /// - /// 获取配置项数量 + /// 查询配置数量 /// - /// 应用Id - /// 应用环境 + /// /// - [HttpGet("item/count")] + [HttpGet("count")] [Produces(typeof(int))] - public async Task GetItemCountAsync(string id, string environment) + public async Task CountAsync([FromQuery] ConfigurationCriteria criteria) { - var result = await _service.GetItemCountAsync(id, environment, HttpContext.RequestAborted); + var result = await _service.CountAsync(criteria, HttpContext.RequestAborted); return Ok(result); } - /// - /// 获取Json格式配置 - /// - /// 应用Id - /// 应用环境 - /// - [HttpGet("item/json")] - [Produces(typeof(string))] - public async Task GetJsonAsync(string id, string environment) - { - var json = await _service.GetItemsInTextAsync(id, environment, "json", HttpContext.RequestAborted); - return Ok(json); - } - /// /// 获取配置节点详情 /// /// 应用Id - /// 应用环境 /// - [HttpGet("detail")] - [Produces] - public async Task GetAsync(string id, string environment) + [HttpGet("{id}")] + [Produces] + public async Task GetAsync(string id) { - var result = await _service.GetDetailAsync(id, environment, HttpContext.RequestAborted); + var result = await _service.GetDetailAsync(id, HttpContext.RequestAborted); return Ok(result); } /// /// 新增配置 /// - /// 应用Id - /// 应用环境 - /// - /// + /// 团队Id + /// 配置基本信息 /// [HttpPost] - public async Task CreateAsync(string id, string environment, [FromHeader(Name = "x-format")] string format, [FromBody] ConfigurationEditDto data) + public async Task CreateAsync(string teamId, [FromBody] ConfigurationEditDto data) { - var result = await _service.CreateAsync(id, environment, format, data, HttpContext.RequestAborted); + var result = await _service.CreateAsync(teamId, data, HttpContext.RequestAborted); Response.Headers.Append("Entry", $"{result}"); return Ok(); } @@ -114,14 +84,12 @@ public async Task CreateAsync(string id, string environment, [Fro /// 更新配置 /// /// 应用Id - /// 应用环境 - /// 数据格式 - /// 数据内容 + /// 配置基本信息 /// - [HttpPut] - public async Task UpdateAsync(string id, string environment, [FromHeader(Name = "x-format")] string format, [FromBody] ConfigurationEditDto data) + [HttpPut("{id}")] + public async Task UpdateAsync(string id, [FromBody] ConfigurationEditDto data) { - await _service.UpdateAsync(id, environment, format, data, HttpContext.RequestAborted); + await _service.UpdateAsync(id, data, HttpContext.RequestAborted); return Ok(); } @@ -129,28 +97,48 @@ public async Task UpdateAsync(string id, string environment, [Fro /// 删除配置 /// /// 应用Id - /// 应用环境 /// - [HttpDelete] - public async Task DeleteAsync(string id, string environment) + [HttpDelete("{id}")] + public async Task DeleteAsync(string id) { - await _service.DeleteAsync(id, environment, HttpContext.RequestAborted); + await _service.DeleteAsync(id, HttpContext.RequestAborted); return Ok(); } /// - /// 更新配置项的值 + /// 设置访问密钥 /// - /// 应用Id - /// 应用环境 - /// 完整Key名称 + /// /// /// - [HttpPut("{key}")] - public async Task UpdateItemValueAsync(string id, string environment, string key, [FromBody] ConfigurationValueUpdateDto data) + [HttpPut("{id}/secret")] + public async Task SetSecretAsync(string id, [FromBody] ConfigurationSecretSetRequestDto data) { - key = HttpUtility.UrlDecode(key); - await _service.UpdateAsync(id, environment, key, data.Value, HttpContext.RequestAborted); + await _service.SetSecretAsync(id, data.Secret, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 禁用配置 + /// + /// + /// + [HttpPut("{id}/disable")] + public async Task DisableAsync(string id) + { + await _service.DisableAsync(id, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 启用配置 + /// + /// + /// + [HttpPut("{id}/enable")] + public async Task EnableAsync(string id) + { + await _service.EnableAsync(id, HttpContext.RequestAborted); return Ok(); } @@ -158,41 +146,95 @@ public async Task UpdateItemValueAsync(string id, string environm /// 发布配置 /// /// 应用Id - /// 应用环境 /// /// - [HttpPost("publish")] - public async Task PublishAsync(string id, string environment, [FromBody] ConfigurationPublishDto data) + [HttpPost("{id}/publish")] + public async Task PublishAsync(string id, [FromBody] ConfigurationPublishRequestDto data) { - await _service.PublishAsync(id, environment, data, HttpContext.RequestAborted); + await _service.PublishAsync(id, data, HttpContext.RequestAborted); return Ok(); } /// - /// 获取发布的配置 + /// 推送到Redis + /// + /// + /// + /// + [HttpPost("{id}/redis")] + public async Task PushRedisAsync(string id, [FromBody] ConfigurationPushRedisRequestDto data) + { + await _service.PushRedisAsync(id, data, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 获取配置项列表 + /// + /// 应用Id + /// + /// + /// + /// + /// + [HttpGet("{id}/item")] + [Produces(typeof(List))] + public async Task GetItemListAsync(string id, string key, int skip = Constants.Query.Skip, int count = Constants.Query.Count, [FromHeader(Name = "x-format")] string format = null) + { + switch (format) + { + case Constants.Configuration.FormatText: + var text = await _service.GetItemsInTextAsync(id, "text", HttpContext.RequestAborted); + return Ok(text); + case Constants.Configuration.FormatJson: + var json = await _service.GetItemsInTextAsync(id, "json", HttpContext.RequestAborted); + return Ok(json); + default: + var result = await _service.GetItemListAsync(id, key, skip, count, HttpContext.RequestAborted); + return Ok(result); + } + } + + /// + /// 获取配置项数量 /// /// 应用Id - /// 应用环境 + /// 关键字 /// - [HttpGet("archive")] - [Produces] - public async Task GetArchivedAsync(string id, string environment) + [HttpGet("{id}/item/count")] + [Produces(typeof(int))] + public async Task GetItemCountAsync(string id, string keyword) { - var result = await _service.GetArchiveAsync(id, environment, HttpContext.RequestAborted); + var result = await _service.GetItemCountAsync(id, keyword, HttpContext.RequestAborted); return Ok(result); } /// - /// 推送到Redis + /// 更新配置项的值 + /// + /// 应用Id + /// 完整Key名称 + /// + /// + [HttpPut("{id}/item/{key}")] + [Consumes("text/plain")] + public async Task UpdateValueAsync(string id, string key, [FromBody] string data) + { + key = HttpUtility.UrlDecode(key); + await _service.UpdateValueAsync(id, key, data, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 更新配置项 /// /// - /// /// /// - [HttpPost("redis")] - public async Task PushRedisAsync(string id, string environment, [FromBody] PushRedisRequestDto data) + [HttpPut("{id}/item")] + public async Task UpdateItemsAsync(string id, [FromBody] ConfigurationItemsUpdateDto data) { - await _service.PushRedisAsync(id, environment, data, HttpContext.RequestAborted); + await _service.UpdateItemsAsync(id, data, HttpContext.RequestAborted); return Ok(); } } \ No newline at end of file diff --git a/Source/Starfish.Webapi/Controllers/EventStreamController.cs b/Source/Starfish.Webapi/Controllers/EventStreamController.cs index 2998819..17ab672 100644 --- a/Source/Starfish.Webapi/Controllers/EventStreamController.cs +++ b/Source/Starfish.Webapi/Controllers/EventStreamController.cs @@ -1,5 +1,4 @@ -using System.Security.Authentication; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Net.Http.Headers; using Nerosoft.Starfish.Application; @@ -32,20 +31,14 @@ public EventStreamController(ConnectionContainer container, ILoggerFactory logge /// /// [Route("/es")] - public async Task HandleAsync(string app, string secret, string env) + public async Task HandleAsync(string id, string teamId, string name, string secret) { - var auth = await AuthAsync(app, secret); - - if (!auth) - { - throw new AuthenticationException(Resources.IDS_ERROR_AUTHORIZE_FAILED); - } - //var environment = HttpContext.Request.Headers[Constants.RequestHeaders.Env]; + var configId = await AuthAsync(id, teamId, name, secret); Response.Headers.Append(HeaderNames.ContentType, "text/event-stream"); Response.Headers.Append(HeaderNames.Connection, "close"); try { - var connection = _container.GetOrAdd(app, env, HttpContext.Connection.Id); + var connection = _container.GetOrAdd(configId, HttpContext.Connection.Id); while (await connection.Channel.Reader.WaitToReadAsync(HttpContext.RequestAborted)) { @@ -71,16 +64,17 @@ public async Task HandleAsync(string app, string secret, string env) finally { Response.Body.Close(); - _container.Remove(app, env, HttpContext.Connection.Id); + _container.Remove(configId, HttpContext.Connection.Id); } } - private Task AuthAsync(string app, string secret) + private Task AuthAsync(string id, string teamId, string name, string secret) { // var app = HttpContext.Request.Headers[Constants.RequestHeaders.App]; // var secret = HttpContext.Request.Headers[Constants.RequestHeaders.Secret]; - var service = HttpContext.RequestServices.GetRequiredService(); - return service.AuthorizeAsync(app, secret, HttpContext.RequestAborted); + var service = HttpContext.RequestServices.GetRequiredService(); + return service.AuthorizeAsync(id, teamId, name, secret, HttpContext.RequestAborted); + } } \ No newline at end of file diff --git a/Source/Starfish.Webapi/Controllers/WebSocketController.cs b/Source/Starfish.Webapi/Controllers/WebSocketController.cs index f30d5ac..f4366f0 100644 --- a/Source/Starfish.Webapi/Controllers/WebSocketController.cs +++ b/Source/Starfish.Webapi/Controllers/WebSocketController.cs @@ -1,5 +1,4 @@ using System.Net.WebSockets; -using System.Security.Authentication; using System.Threading.Channels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -30,26 +29,21 @@ public WebSocketController(ConnectionContainer container) /// /// [Route("/ws")] - public async Task HandleAsync(string app, string secret, string env) + public async Task HandleAsync(string id, string teamId, string name, string secret) { if (HttpContext.WebSockets.IsWebSocketRequest) { - var auth = await AuthAsync(app, secret); - - if (!auth) - { - throw new AuthenticationException(Resources.IDS_ERROR_AUTHORIZE_FAILED); - } + var configId = await AuthAsync(id, teamId, name, secret); using var socket = await HttpContext.WebSockets.AcceptWebSocketAsync(); - var connection = _container.GetOrAdd(app, env, HttpContext.Connection.Id); + var connection = _container.GetOrAdd(configId, HttpContext.Connection.Id); await Task.WhenAny(MonitorChannelAsync(connection.Channel, socket), MonitorClientAsync(socket)); await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); - _container.Remove(app, env, HttpContext.Connection.Id); + _container.Remove(configId, HttpContext.Connection.Id); } else { @@ -97,12 +91,13 @@ async Task MonitorClientAsync(WebSocket webSocket) } } - private Task AuthAsync(string app, string secret) + private Task AuthAsync(string id, string teamId, string name, string secret) { // var app = HttpContext.Request.Headers[Constants.RequestHeaders.App]; // var secret = HttpContext.Request.Headers[Constants.RequestHeaders.Secret]; - var service = HttpContext.RequestServices.GetRequiredService(); - return service.AuthorizeAsync(app, secret, HttpContext.RequestAborted); + var service = HttpContext.RequestServices.GetRequiredService(); + return service.AuthorizeAsync(id, teamId, name, secret, HttpContext.RequestAborted); + } } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Layout/MainLayout.razor b/Source/Starfish.Webapp/Layout/MainLayout.razor index ff6e614..857d1b0 100644 --- a/Source/Starfish.Webapp/Layout/MainLayout.razor +++ b/Source/Starfish.Webapp/Layout/MainLayout.razor @@ -29,7 +29,7 @@ @(Resources.IDS_MENU_TEXT_HOME) - @(Resources.IDS_MENU_TEXT_APPS) + @(Resources.IDS_MENU_TEXT_CONFIGS) @if (Identity?.IsInRole("SA") == true) { @(Resources.IDS_MENU_TEXT_USER) diff --git a/Source/Starfish.Webapp/Pages/Apps/Edit.razor b/Source/Starfish.Webapp/Pages/Apps/Edit.razor deleted file mode 100644 index ee2fb62..0000000 --- a/Source/Starfish.Webapp/Pages/Apps/Edit.razor +++ /dev/null @@ -1,185 +0,0 @@ -@implements IDialogContentComponent - -@inject IAppsApi AppsApi -@inject ITeamApi TeamApi - - - - - - @Dialog.Instance.Parameters.Title - - - - - - - @if (string.IsNullOrEmpty(Content)) - { - - } - - - - @if (string.IsNullOrEmpty(Content)) - { - - } - - - - - - @(Resources.IDS_COMMON_SAVE) - @(Resources.IDS_COMMON_CANCEL) - - -@code { - - [Parameter] - public string Content { get; set; } - - [CascadingParameter] - public FluentDialog Dialog { get; set; } = default!; - - private bool Loading { get; set; } - - private List Teams { get; } = []; - - /// - /// 团队Id - /// - private string TeamId { get; set; } - - /// - /// 应用名称 - /// - private string Name { get; set; } = default!; - - /// - /// 密钥 - /// - private string Secret { get; set; } - - /// - /// 应用描述 - /// - private string Description { get; set; } - - protected override async Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - - var tasks = new List - { - string.IsNullOrEmpty(Content) ? LoadTeamsAsync() : LoadDetailAsync(Content) - }; - - await Task.WhenAll(tasks); - } - - private async Task SaveAsync() - { - try - { - Loading = true; - - if (!string.IsNullOrEmpty(Content)) - { - var request = new AppInfoUpdateDto() - { - Name = Name, - Description = Description - }; - await AppsApi.UpdateAsync(Content, request) - .EnsureSuccess(); - } - else - { - var request = new AppInfoCreateDto() - { - TeamId = TeamId, - Name = Name, - Secret = Secret, - Description = Description - }; - await AppsApi.CreateAsync(request) - .EnsureSuccess(); - } - - await Dialog.CloseAsync(Content); - } - catch (Exception exception) - { - exception.Send(); - } - finally - { - Loading = false; - } - } - - private async Task CancelAsync() - { - await Dialog.CancelAsync(); - } - - private async Task LoadTeamsAsync() - { - await TeamApi.QueryAsync(new TeamCriteria(), 1, 100) - .EnsureSuccess(result => - { - if (result == null) - { - return; - } - - Teams.Clear(); - Teams.AddRange(result); - if (result.Count > 0) - { - TeamId = result[0].Id.ToString(); - } - }) - .Guard(); - } - - private async Task LoadDetailAsync(string id) - { - if (string.IsNullOrEmpty(id)) - { - return; - } - - await AppsApi.GetAsync(id) - .EnsureSuccess(result => - { - if (result == null) - { - return; - } - - Content = result.Id; - Name = result.Name; - Description = result.Description; - }) - .Guard(async _ => - { - await Dialog.CancelAsync(); - }); - } - -} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Apps/Index.razor b/Source/Starfish.Webapp/Pages/Apps/Index.razor deleted file mode 100644 index bf5406f..0000000 --- a/Source/Starfish.Webapp/Pages/Apps/Index.razor +++ /dev/null @@ -1,166 +0,0 @@ -@page "/apps" - -@attribute [Authorize] - -@inject IDialogService DialogService -@inject NavigationManager Navigation -@inject IAppsApi Api - - - @(Resources.IDS_MENU_TEXT_HOME) - @(Resources.IDS_MENU_TEXT_APPS) - - - - - - - - - - - - - @(context.Name) - - - - - - - - - - - - - - - - - - - - - -@code { - - [CascadingParameter] - private Task AuthenticationState { get; set; } - - private UserPrincipal User { get; set; } - - private GridItemsProvider _provider; - - private PaginationState Pagination { get; } = new() { ItemsPerPage = Constants.Query.Count }; - - private AppInfoCriteria Criteria { get; } = new(); - - private int Total { get; set; } - - protected override async Task OnInitializedAsync() - { - var user = await AuthenticationState; - - User = new UserPrincipal(user.User); - - _provider = async request => - { - List items = null; - var tasks = new List - { - Api.QueryAsync(Criteria, request.StartIndex, Pagination.ItemsPerPage, request.CancellationToken) - .EnsureSuccess(result => items = result, request.CancellationToken) - }; - - if (request.StartIndex == 0) - { - tasks.Add(Api.CountAsync(Criteria, request.CancellationToken).EnsureSuccess(request.CancellationToken)); - } - - await Task.WhenAll(tasks).Guard(); - await Pagination.SetTotalItemCountAsync(Total); - return GridItemsProviderResult.From(items, Total); - }; - } - - private Task OnDetailButtonClicked(string id) - { - return DialogService.ShowDialogAsync(id, new DialogParameters { Title = Resources.IDS_APPS_DETAIL_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); - } - - private async Task OnGotoConfigurationClicked(string id) - { - Navigation.NavigateTo($"/apps/{id}/configs"); - await Task.CompletedTask; - } - - private async Task OnEditButtonClicked(string id) - { - var title = string.IsNullOrEmpty(id) ? Resources.IDS_APPS_EDIT_TITLE_ADD : Resources.IDS_APPS_EDIT_TITLE_EDIT; - var dialog = await DialogService.ShowDialogAsync(id, new DialogParameters { Title = title, PreventDismissOnOverlayClick = true }); - var result = await dialog.Result; - if (result.Cancelled) - { - await Pagination.SetCurrentPageIndexAsync(0); - } - } - - private async Task OnDeleteButtonClicked(string id, string name) - { - var confirmationMessage = string.Format(Resources.IDS_APPS_INDEX_REMOVE_CONFIRMATION_MESSAGE, name); - var confirmation = await DialogService.ShowConfirmationAsync(confirmationMessage, primaryText: Resources.IDS_COMMON_YES, - secondaryText: Resources.IDS_COMMON_NO, title: Resources.IDS_APPS_INDEX_REMOVE_CONFIRMATION_TITLE); - var result = await confirmation.Result; - if (!result.Cancelled) - { - await Api.DeleteAsync(id).EnsureSuccess().Guard(); - await Pagination.SetCurrentPageIndexAsync(0); - } - } - - private async Task OnResetSecretClicked(string id) - { - await DialogService.ShowDialogAsync(id, new DialogParameters { PreventDismissOnOverlayClick = true }); - } - - private async Task OnSearchClicked() - { - await Pagination.SetCurrentPageIndexAsync(0); - } - - private async Task OnStatusChanged(AppInfoItemDto context, bool status) - { - try - { - await Api.ChangeStatusAsync(context.Id, status ? "enable" : "disable").EnsureSuccess(); - context.Status = status ? "Enabled" : "Disabled"; - } - catch (Exception exception) - { - exception.Send(); - } - } - -} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Apps/Detail.razor b/Source/Starfish.Webapp/Pages/Configs/Detail.razor similarity index 68% rename from Source/Starfish.Webapp/Pages/Apps/Detail.razor rename to Source/Starfish.Webapp/Pages/Configs/Detail.razor index baed1c6..53019b6 100644 --- a/Source/Starfish.Webapp/Pages/Apps/Detail.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Detail.razor @@ -1,10 +1,10 @@ @implements IDialogContentComponent -@inject IAppsApi AppsApi +@inject IConfigurationApi ConfigurationApi - + @Dialog.Instance.Parameters.Title @@ -15,24 +15,24 @@ @if (Loading) { - + } else { - + - + + Label="@(Resources.IDS_CONFIG_DETAIL_DIALOG_LABEL_STATUS)" ReadOnly="true"/> - + } @@ -43,6 +43,7 @@ @code { + [Parameter] public string Content { get; set; } @@ -51,7 +52,7 @@ private bool Loading { get; set; } - private AppInfoDetailDto Data { get; } = new(); + private ConfigurationDto Data { get; } = new(); protected override async Task OnInitializedAsync() { @@ -59,11 +60,13 @@ { Loading = true; - await AppsApi.GetAsync(Content).EnsureSuccess(result => + await ConfigurationApi.GetAsync(Content).EnsureSuccess(result => { Data.Name = result.Name; Data.Description = result.Description; - Data.Status = result.Status; + Data.StatusName = result.StatusName; + Data.Version = result.Version; + Data.PublishTime = result.PublishTime; }); } catch (Exception exception) @@ -80,4 +83,5 @@ { await Dialog.CancelAsync(); } + } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/Edit.razor b/Source/Starfish.Webapp/Pages/Configs/Edit.razor index 285eb74..19a73b5 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Edit.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Edit.razor @@ -1,11 +1,11 @@ -@using Nerosoft.Starfish.Common -@implements IDialogContentComponent +@implements IDialogContentComponent @inject IConfigurationApi ConfigurationApi +@inject ITeamApi TeamApi - + @Dialog.Instance.Parameters.Title @@ -14,13 +14,31 @@ - + @if (string.IsNullOrEmpty(Content)) + { + + } -
- -
+ + + @if (string.IsNullOrEmpty(Content)) + { + + } +
@@ -32,68 +50,75 @@ @code { [Parameter] - public EditDialogArgs Content { get; set; } + public string Content { get; set; } [CascadingParameter] public FluentDialog Dialog { get; set; } = default!; - private string Mode => Content?.Properties?.TryGetValue("mode") as string; + private bool Loading { get; set; } - private string Format => Content?.Properties?.TryGetValue("format") as string; + private List Teams { get; } = []; - private StandaloneCodeEditor _editor = null!; + /// + /// 团队Id + /// + private string TeamId { get; set; } - protected override async Task OnInitializedAsync() - { - if (Mode == "update") - { - await LoadValueAsync(); - } - } + /// + /// 应用名称 + /// + private string Name { get; set; } = default!; + + /// + /// 密钥 + /// + private string Secret { get; set; } - private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) + /// + /// 应用描述 + /// + private string Description { get; set; } + + protected override async Task OnInitializedAsync() { - var options = new StandaloneEditorConstructionOptions - { - AutomaticLayout = true, - Theme = "vs-dark" - }; + await base.OnInitializedAsync(); - options.Language = Format switch + var tasks = new List { - Constants.Configuration.FormatJson => "json", - Constants.Configuration.FormatText => "text", - _ => options.Language + string.IsNullOrEmpty(Content) ? LoadTeamsAsync() : LoadDetailAsync(Content) }; - return options; + await Task.WhenAll(tasks); } - private async Task EditorOnDidInit() - { - await Task.CompletedTask; - } - - private bool Loading { get; set; } - private async Task SaveAsync() { try { Loading = true; - var value = await _editor.GetValue(); - var request = new ConfigurationEditDto() + + if (!string.IsNullOrEmpty(Content)) { - Type = "diff", - Data = Cryptography.Base64.Encrypt(value) - }; - var task = Mode switch + var request = new ConfigurationEditDto + { + Name = Name, + Description = Description + }; + await ConfigurationApi.UpdateAsync(Content, request) + .EnsureSuccess(); + } + else { - "create" => ConfigurationApi.CreateAsync(Content.AppId, Content.Environment, Format, request).EnsureSuccess(), - "update" => ConfigurationApi.UpdateAsync(Content.AppId, Content.Environment, Format, request).EnsureSuccess(), - _ => Task.CompletedTask - }; - await task; + var request = new ConfigurationEditDto() + { + Name = Name, + Secret = Secret, + Description = Description + }; + await ConfigurationApi.CreateAsync(TeamId, request) + .EnsureSuccess(); + } + await Dialog.CloseAsync(Content); } catch (Exception exception) @@ -111,14 +136,49 @@ await Dialog.CancelAsync(); } - private Task LoadValueAsync() + private async Task LoadTeamsAsync() { - return ConfigurationApi.GetItemsAsync(Content.AppId, Content.Environment, Format) - .EnsureSuccess(result=> + await TeamApi.QueryAsync(new TeamCriteria(), 1, 100) + .EnsureSuccess(result => + { + if (result == null) + { + return; + } + + Teams.Clear(); + Teams.AddRange(result); + if (result.Count > 0) { - var value = Cryptography.Base64.Decrypt(result); - _editor.SetValue(value); - }) - .Guard(); + TeamId = result[0].Id.ToString(); + } + }) + .Guard(); + } + + private async Task LoadDetailAsync(string id) + { + if (string.IsNullOrEmpty(id)) + { + return; + } + + await ConfigurationApi.GetAsync(id) + .EnsureSuccess(result => + { + if (result == null) + { + return; + } + + Content = result.Id; + Name = result.Name; + Description = result.Description; + }) + .Guard(async _ => + { + await Dialog.CancelAsync(); + }); } + } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/EditDialogArgs.cs b/Source/Starfish.Webapp/Pages/Configs/EditDialogArgs.cs index 2e8e188..96281f0 100644 --- a/Source/Starfish.Webapp/Pages/Configs/EditDialogArgs.cs +++ b/Source/Starfish.Webapp/Pages/Configs/EditDialogArgs.cs @@ -2,15 +2,12 @@ public class EditDialogArgs { - public EditDialogArgs(string appId, string environment) + public EditDialogArgs(string id) { - AppId = appId; - Environment = environment; + Id = id; } - public string AppId { get; set; } - - public string Environment { get; set; } + public string Id { get; set; } public Dictionary Properties { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/EditItems.razor b/Source/Starfish.Webapp/Pages/Configs/EditItems.razor new file mode 100644 index 0000000..e0b979e --- /dev/null +++ b/Source/Starfish.Webapp/Pages/Configs/EditItems.razor @@ -0,0 +1,111 @@ +@using Nerosoft.Starfish.Common +@implements IDialogContentComponent + +@inject IConfigurationApi ConfigurationApi + + + + + + @Dialog.Instance.Parameters.Title + + + + + + +
+ +
+
+
+ + + @(Resources.IDS_COMMON_SAVE) + @(Resources.IDS_COMMON_CANCEL) + + +@code { + + [Parameter] + public EditDialogArgs Content { get; set; } + + [CascadingParameter] + public FluentDialog Dialog { get; set; } = default!; + + private string Format => Content?.Properties?.TryGetValue("format") as string; + + private StandaloneCodeEditor _editor = null!; + + protected override async Task OnInitializedAsync() + { + await LoadValueAsync(); + } + + private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) + { + var options = new StandaloneEditorConstructionOptions + { + AutomaticLayout = true, + Theme = "vs-dark" + }; + + options.Language = Format switch + { + Constants.Configuration.FormatJson => "json", + Constants.Configuration.FormatText => "text", + _ => options.Language + }; + + return options; + } + + private async Task EditorOnDidInit() + { + await Task.CompletedTask; + } + + private bool Loading { get; set; } + + private async Task SaveAsync() + { + try + { + Loading = true; + var value = await _editor.GetValue(); + var request = new ConfigurationItemsUpdateDto() + { + Type = Format, + Mode = "diff", + Data = Cryptography.Base64.Encrypt(value) + }; + await ConfigurationApi.UpdateItemsAsync(Content.Id, request).EnsureSuccess(); + await Dialog.CloseAsync(Content); + } + catch (Exception exception) + { + exception.Send(); + } + finally + { + Loading = false; + } + } + + private async Task CancelAsync() + { + await Dialog.CancelAsync(); + } + + private Task LoadValueAsync() + { + return ConfigurationApi.GetItemsAsync(Content.Id, Format) + .EnsureSuccess(result => + { + var value = Cryptography.Base64.Decrypt(result); + _editor.SetValue(value); + }) + .Guard(); + } + +} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/EditValue.razor b/Source/Starfish.Webapp/Pages/Configs/EditValue.razor index 1ef2e2e..6726d52 100644 --- a/Source/Starfish.Webapp/Pages/Configs/EditValue.razor +++ b/Source/Starfish.Webapp/Pages/Configs/EditValue.razor @@ -19,7 +19,7 @@ + @bind-Value="Value"/>
@@ -40,11 +40,11 @@ private string Key => Content?.Properties?.TryGetValue("key") as string; - private ConfigurationValueUpdateDto Request { get; } = new(); + private string Value { get; set; } protected override async Task OnInitializedAsync() { - Request.Value = Content?.Properties?.TryGetValue("value") as string; + Value = Content?.Properties?.TryGetValue("value") as string; await Task.CompletedTask; } @@ -53,7 +53,7 @@ try { Loading = true; - await ConfigurationApi.UpdateItemValueAsync(Content.AppId, Content.Environment, Key, Request) + await ConfigurationApi.UpdateValueAsync(Content.Id, Key, Value) .EnsureSuccess(); await Dialog.CloseAsync(Content); } diff --git a/Source/Starfish.Webapp/Pages/Configs/Index.razor b/Source/Starfish.Webapp/Pages/Configs/Index.razor index 3b9a05d..15d4740 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Index.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Index.razor @@ -1,116 +1,83 @@ -@page "/apps/{id}/configs" +@page "/configs" @attribute [Authorize] @inject IDialogService DialogService @inject IConfigurationApi ConfigurationApi -@inject IAppsApi AppsApi +@inject NavigationManager Navigation @(Resources.IDS_MENU_TEXT_HOME) - @(Resources.IDS_MENU_TEXT_APPS) - @(Resources.IDS_BREADCRUMB_CONFIG) + @(Resources.IDS_MENU_TEXT_CONFIGS) - - - - - - - - - - - - - - - - - - - - - - - -
- - - - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_APP_NAME, AppDetail?.Name) - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_APP_CODE, AppDetail?.Id) - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_APP_STATUS, AppDetail?.StatusDescription) - - @AppDetail?.Description - - - @if (ConfigurationDetail != null) - { - - - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_VERSION, ConfigurationDetail?.Version ?? "--") - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_PUBLISH_TIME, ConfigurationDetail?.PublishTime) - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_UPDATE_TIME, ConfigurationDetail?.UpdateTime) - - - } - - - - @(Resources.IDS_CONFIG_INDEX_BUTTON_SYNC_REDIS) - @(Resources.IDS_CONFIG_INDEX_BUTTON_DELETE) - - @if (ConfigurationDetail?.Status == "Pending") - { - @(Resources.IDS_CONFIG_INDEX_BUTTON_PUBLISH) - } - - - - -
-
-
- + + + + + + + + + + + @(context.Name) + + + + + + + + + + + + + + + + + + + + @code { - [Parameter] - public string Id { get; set; } - [CascadingParameter] private Task AuthenticationState { get; set; } private UserPrincipal Identity { get; set; } - private GridItemsProvider _provider; + private GridItemsProvider _provider; private PaginationState Pagination { get; } = new() { ItemsPerPage = Constants.Query.Count }; - private int Total { get; set; } - - private ConfigurationDetailDto ConfigurationDetail { get; set; } - - private AppInfoDetailDto AppDetail { get; set; } + private ConfigurationCriteria Criteria { get; } = new(); - private string Environment { get; set; } = "DEV"; + private int Total { get; set; } protected override async Task OnInitializedAsync() { @@ -118,22 +85,19 @@ Identity = new UserPrincipal(user.User); - await LoadAppDetailAsync(); - await LoadConfigurationDetailAsync(); - _provider = async request => { - List items = null; + List items = null; var tasks = new List { - ConfigurationApi.GetItemListAsync(Id, Environment, request.StartIndex, Pagination.ItemsPerPage, request.CancellationToken) + ConfigurationApi.QueryAsync(Criteria, request.StartIndex, Pagination.ItemsPerPage, request.CancellationToken) .EnsureSuccess(result => items = result, request.CancellationToken) }; if (request.StartIndex == 0) { tasks.Add( - ConfigurationApi.GetItemCountAsync(Id, Environment, request.CancellationToken) + ConfigurationApi.CountAsync(Criteria, request.CancellationToken) .EnsureSuccess(result => Total = result, request.CancellationToken) ); } @@ -144,117 +108,48 @@ }; } - private async Task OnSelectedEnvironmentChanged(string value) + private async Task OnSearchClicked() { - Environment = value; - var tasks = new List - { - Pagination.SetCurrentPageIndexAsync(0), - LoadConfigurationDetailAsync() - }; - await Task.WhenAll(tasks).Guard(); - } - - private Task LoadConfigurationDetailAsync(CancellationToken cancellationToken = default) - { - return ConfigurationApi.GetAsync(Id, Environment, cancellationToken) - .EnsureSuccess(result => ConfigurationDetail = result, cancellationToken) - .Guard(); - } - - private Task LoadAppDetailAsync() - { - return AppsApi.GetAsync(Id) - .EnsureSuccess(result => AppDetail = result) - .Guard(); - } - - private async Task OnEditJsonClicked() - { - var args = new EditDialogArgs(Id, Environment) - { - Properties = new Dictionary - { - ["mode"] = ConfigurationDetail == null ? "create" : "update", - ["format"] = Constants.Configuration.FormatJson - } - }; - var title = ConfigurationDetail == null ? Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_CREATE_FROM_JSON : Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_AS_JSON; - - var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = title, Width = "calc(100% - 2px)", Height = "calc(100% - 2px)", PreventDismissOnOverlayClick = true }); - var result = await dialog.Result; - if (!result.Cancelled) - { - await Pagination.SetCurrentPageIndexAsync(0); - } + await Pagination.SetCurrentPageIndexAsync(0); } - private async Task OnEditTextClicked() + private async Task OnEditButtonClicked(string id) { - var args = new EditDialogArgs(Id, Environment) - { - Properties = new Dictionary - { - ["mode"] = ConfigurationDetail == null ? "create" : "update", - ["format"] = Constants.Configuration.FormatText - } - }; - - var title = ConfigurationDetail == null ? Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_CREATE_FROM_TEXT : Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_AS_TEXT; - - var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = title, Width = "calc(100% - 2px)", Height = "calc(100% - 2px)", PreventDismissOnOverlayClick = true }); + var title = string.IsNullOrEmpty(id) ? Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_ADD : Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT; + var dialog = await DialogService.ShowDialogAsync(id, new DialogParameters { Title = title, PreventDismissOnOverlayClick = true }); var result = await dialog.Result; - if (!result.Cancelled) + if (result.Cancelled) { await Pagination.SetCurrentPageIndexAsync(0); } } - private async Task OnEditValueClicked(string key, string value) + private async Task OnGotoConfigurationClicked(string id) { - var args = new EditDialogArgs(Id, Environment) - { - Properties = new Dictionary - { - ["key"] = key, - ["value"] = value - } - }; - - var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_VALUE, PreventDismissOnOverlayClick = true }); - var result = await dialog.Result; - if (!result.Cancelled) - { - await Pagination.SetCurrentPageIndexAsync(0); - } + Navigation.NavigateTo($"/configs/{id}"); + await Task.CompletedTask; } - - private async Task OnPublishClicked() + + private Task OnDetailButtonClicked(string id) { - var args = new EditDialogArgs(Id, Environment); - var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_PUBLISH_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); - var result = await dialog.Result; - if (!result.Cancelled) - { - await LoadConfigurationDetailAsync(); - } + return DialogService.ShowDialogAsync(id, new DialogParameters { Title = Resources.IDS_CONFIG_DETAIL_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); } - - private async Task OnSyncRedisClicked() + + private async Task OnResetSecretClicked(string id) { - var args = new EditDialogArgs(Id, Environment); - await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_SYNC_REDIS_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); + await DialogService.ShowDialogAsync(id, new DialogParameters { PreventDismissOnOverlayClick = true }); } - private async Task OnDeleteClicked() + private async Task OnDeleteButtonClicked(string id, string name) { - var confirmation = await DialogService.ShowConfirmationAsync(Resources.IDS_CONFIG_DELETE_CONFIRM_MESSAGE, primaryText: Resources.IDS_COMMON_YES, secondaryText: Resources.IDS_COMMON_NO, title: Resources.IDS_CONFIG_DELETE_CONFIRM_TITLE); + var message = string.Format(Resources.IDS_CONFIG_DELETE_CONFIRM_MESSAGE, name); + var confirmation = await DialogService.ShowConfirmationAsync(message, primaryText: Resources.IDS_COMMON_YES, secondaryText: Resources.IDS_COMMON_NO, title: Resources.IDS_CONFIG_DELETE_CONFIRM_TITLE); var result = await confirmation.Result; if (!result.Cancelled) { try { - await ConfigurationApi.DeleteAsync(Id, Environment) + await ConfigurationApi.DeleteAsync(id) .EnsureSuccess(); await Pagination.SetCurrentPageIndexAsync(0); StateHasChanged(); @@ -266,4 +161,16 @@ } } + private async Task OnStatusChanged(ConfigurationDto context, bool status) + { + try + { + await ConfigurationApi.ChangeStatusAsync(context.Id, status ? "enable" : "disable").EnsureSuccess(); + context.Status = status ? "Pending" : "Disabled"; + } + catch (Exception exception) + { + exception.Send(); + } + } } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/Items.razor b/Source/Starfish.Webapp/Pages/Configs/Items.razor new file mode 100644 index 0000000..0a73b0c --- /dev/null +++ b/Source/Starfish.Webapp/Pages/Configs/Items.razor @@ -0,0 +1,174 @@ +@page "/configs/{id}" + +@attribute [Authorize] + +@inject IDialogService DialogService +@inject IConfigurationApi ConfigurationApi + + + @(Resources.IDS_MENU_TEXT_HOME) + @(Resources.IDS_MENU_TEXT_CONFIGS) + @(Resources.IDS_BREADCRUMB_CONFIG) + + + + + + + + + + + + + + + + + + + + + + +@code { + + [Parameter] + public string Id { get; set; } + + [CascadingParameter] + private Task AuthenticationState { get; set; } + + private UserPrincipal Identity { get; set; } + + private string Keyword { get; set; } + + private GridItemsProvider _provider; + + private PaginationState Pagination { get; } = new() { ItemsPerPage = Constants.Query.Count }; + + private int Total { get; set; } + + private ConfigurationDto Configuration { get; set; } + + protected override async Task OnInitializedAsync() + { + var user = await AuthenticationState; + + Identity = new UserPrincipal(user.User); + + await LoadConfigurationDetailAsync(); + + _provider = async request => + { + List items = null; + var tasks = new List + { + ConfigurationApi.GetItemListAsync(Id, Keyword, request.StartIndex, Pagination.ItemsPerPage, request.CancellationToken) + .EnsureSuccess(result => items = result, request.CancellationToken) + }; + + if (request.StartIndex == 0) + { + tasks.Add( + ConfigurationApi.GetItemCountAsync(Id, request.CancellationToken) + .EnsureSuccess(result => Total = result, request.CancellationToken) + ); + } + + await Task.WhenAll(tasks).Guard(); + await Pagination.SetTotalItemCountAsync(Total); + return GridItemsProviderResult.From(items, Total); + }; + } + + private async Task OnEditClicked(string format) + { + var args = new EditDialogArgs(Id) + { + Properties = new Dictionary + { + ["format"] = format //Constants.Configuration.FormatText + } + }; + + var title = format switch + { + Constants.Configuration.FormatText => Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_AS_TEXT, + Constants.Configuration.FormatJson => Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_AS_JSON, + _ => string.Empty + }; + + var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = title, Width = "calc(100% - 2px)", Height = "calc(100% - 2px)", PreventDismissOnOverlayClick = true }); + var result = await dialog.Result; + if (!result.Cancelled) + { + await Pagination.SetCurrentPageIndexAsync(0); + } + } + + private async Task OnEditValueClicked(string key, string value) + { + var args = new EditDialogArgs(Id) + { + Properties = new Dictionary + { + ["key"] = key, + ["value"] = value + } + }; + + var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT_VALUE, PreventDismissOnOverlayClick = true }); + var result = await dialog.Result; + if (!result.Cancelled) + { + await Pagination.SetCurrentPageIndexAsync(0); + } + } + + private async Task OnPublishClicked() + { + var args = new EditDialogArgs(Id); + var dialog = await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_PUBLISH_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); + var result = await dialog.Result; + if (!result.Cancelled) + { + await LoadConfigurationDetailAsync(); + } + } + + private async Task OnSyncRedisClicked() + { + var args = new EditDialogArgs(Id); + await DialogService.ShowDialogAsync(args, new DialogParameters { Title = Resources.IDS_CONFIG_SYNC_REDIS_DIALOG_TITLE, PreventDismissOnOverlayClick = true }); + } + + private async Task OnSearchClicked() + { + await Pagination.SetCurrentPageIndexAsync(0); + } + + private Task LoadConfigurationDetailAsync(CancellationToken cancellationToken = default) + { + return ConfigurationApi.GetAsync(Id, cancellationToken) + .EnsureSuccess(result => Configuration = result, cancellationToken) + .Guard(); + } + +} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/Publish.razor b/Source/Starfish.Webapp/Pages/Configs/Publish.razor index 6efff7b..f2bd4c8 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Publish.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Publish.razor @@ -38,7 +38,7 @@ private bool Loading { get; set; } - private ConfigurationPublishDto Request { get; } = new(); + private ConfigurationPublishRequestDto Request { get; } = new(); private async Task PublishAsync() { @@ -46,7 +46,7 @@ { Loading = true; - await ConfigurationApi.PublishAsync(Content.AppId, Content.Environment, Request) + await ConfigurationApi.PublishAsync(Content.Id, Request) .EnsureSuccess(); await Dialog.CloseAsync(Content); diff --git a/Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor similarity index 78% rename from Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor rename to Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor index ca2c9d2..7715eb3 100644 --- a/Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor +++ b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor @@ -1,12 +1,12 @@ @implements IDialogContentComponent -@inject IAppsApi AppsApi +@inject IConfigurationApi Api - @(Resources.IDS_APPS_RESET_SECRET_DIALOG_TITLE) + @(Resources.IDS_CONFIG_RESET_SECRET_DIALOG_TITLE) @@ -14,9 +14,9 @@ - @(Resources.IDS_APPS_RESET_SECRET_DIALOG_TIPS) + @(Resources.IDS_CONFIG_RESET_SECRET_DIALOG_TIPS) @@ -43,13 +43,13 @@ { Loading = true; - var data = new AppInfoSetSecretDto + var data = new ConfigurationSecretSetRequestDto { Secret = Secret }; - await AppsApi.SetSecretAsync(Content, data) - .EnsureSuccess(); + await Api.SetSecretAsync(Content, data) + .EnsureSuccess(); await Dialog.CloseAsync(Content); } diff --git a/Source/Starfish.Webapp/Pages/Configs/Revision.razor b/Source/Starfish.Webapp/Pages/Configs/Revision.razor index adc8b38..17ad101 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Revision.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Revision.razor @@ -1,15 +1,12 @@ -@page "/apps/{appId:long}/configs/{configId}/revision" +@page "/configs/{id}/revision" @(Resources.IDS_MENU_TEXT_HOME) - @(Resources.IDS_MENU_TEXT_APPS) - @(Resources.IDS_BREADCRUMB_CONFIG) + @(Resources.IDS_MENU_TEXT_CONFIGS) + @(Resources.IDS_BREADCRUMB_CONFIG) @code { [Parameter] - public string AppId { get; set; } - - [Parameter] - public long ConfigId { get; set; } + public string Id { get; set; } } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/SyncRedis.razor b/Source/Starfish.Webapp/Pages/Configs/SyncRedis.razor index 18b468b..4d3901e 100644 --- a/Source/Starfish.Webapp/Pages/Configs/SyncRedis.razor +++ b/Source/Starfish.Webapp/Pages/Configs/SyncRedis.razor @@ -42,7 +42,7 @@ private bool Loading { get; set; } - private PushRedisRequestDto Request { get; } = new(); + private ConfigurationPushRedisRequestDto Request { get; } = new(); private async Task SaveAsync() { @@ -50,7 +50,7 @@ { Loading = true; - await ConfigurationApi.PushRedisAsync(Content.AppId, Content.Environment, Request) + await ConfigurationApi.PushRedisAsync(Content.Id, Request) .EnsureSuccess(); await Dialog.CloseAsync(Content); diff --git a/Source/Starfish.Webapp/Pages/Team/Detail.razor b/Source/Starfish.Webapp/Pages/Team/Detail.razor index 399a988..e8dc19b 100644 --- a/Source/Starfish.Webapp/Pages/Team/Detail.razor +++ b/Source/Starfish.Webapp/Pages/Team/Detail.razor @@ -1,7 +1,6 @@ @page "/team/{id}" @inject ITeamApi TeamApi -@inject IAppsApi AppsApi @inject IDialogService DialogService @@ -13,15 +12,15 @@ - + @string.Format(Resources.IDS_TEAM_DETAIL_LABEL_ALIAS, Data.Id) @string.Format(Resources.IDS_TEAM_DETAIL_LABEL_CREATE_TIME, Data.CreateTime) @string.Format(Resources.IDS_TEAM_DETAIL_LABEL_UPDATE_TIME, Data.UpdateTime) - + @Data.Description @if (Data.OwnerId != Identity?.UserId) { - + @(Resources.IDS_COMMON_OPERATIONS) @(Resources.IDS_TEAM_DETAIL_BUTTON_EDIT) @@ -31,26 +30,15 @@
- - - - - - - - - - - - - - - - - - - - + + + + + + + + +
@@ -69,10 +57,6 @@ private ObservableRangeCollection Members { get; } = []; - private ObservableRangeCollection Apps { get; } = []; - - private IQueryable QueryableApps => Apps.AsQueryable(); - private IQueryable QueryableMembers => Members.AsQueryable(); protected override async Task OnInitializedAsync() @@ -89,8 +73,7 @@ var tasks = new List { LoadDetailAsync(), - LoadMembersAsync(), - LoadAppsAsync() + LoadMembersAsync() }; await InvokeAsync(() => Task.WhenAll(tasks)); @@ -117,20 +100,6 @@ .EnsureSuccess(result => Members.ReplaceRange(result)); } - private Task LoadAppsAsync() - { - try - { - var criteria = new AppInfoCriteria { TeamId = Id }; - return AppsApi.QueryAsync(criteria, 0, 100) - .EnsureSuccess(result => Apps.ReplaceRange(result)); - } - catch - { - return Task.CompletedTask; - } - } - private async Task OnRemoveMemberClicked(string userId) { var confirmation = await DialogService.ShowConfirmationAsync(Resources.IDS_TEAM_DETAIL_REMOVE_CONFIRMATION_MESSAGE, primaryText: Resources.IDS_COMMON_YES, secondaryText: Resources.IDS_COMMON_NO, title: Resources.IDS_TEAM_DETAIL_REMOVE_CONFIRMATION_TITLE); @@ -166,4 +135,5 @@ { await DialogService.ShowDialogAsync(Id, new DialogParameters { Title = Resources.IDS_TEAM_EDIT_TITLE_EDIT, PreventDismissOnOverlayClick = true }); } + } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/User/ResetPassword.razor b/Source/Starfish.Webapp/Pages/User/ResetPassword.razor index a1cc389..fa71f12 100644 --- a/Source/Starfish.Webapp/Pages/User/ResetPassword.razor +++ b/Source/Starfish.Webapp/Pages/User/ResetPassword.razor @@ -6,7 +6,7 @@ - @(Resources.IDS_APPS_RESET_SECRET_DIALOG_TITLE) + @(Resources.IDS_USER_RESET_PASSWORD_DIALOG_TITLE)
diff --git a/Source/Starfish.Webapp/Properties/Resources.resx b/Source/Starfish.Webapp/Properties/Resources.resx index a9e137d..b20cb57 100644 --- a/Source/Starfish.Webapp/Properties/Resources.resx +++ b/Source/Starfish.Webapp/Properties/Resources.resx @@ -117,78 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - App detail - - - Code - - - Description - - - Name - - - Status - - - Team - - - Code - - - Description - - - Name - - - Secret - - - Select a team - - - Add app - - - Edit app - - - Add app - - - Code - - - App Id - - - Name - - - Status - - - Team - - - Are you sure to remove this app '{0}'? - - - Remove App - - - The system will encrypt the secret and can not be decrypted. You should keep the secret yourself. If you forget the origin secret, please reset it. - - - Reset secret - - - Detail - Configuration @@ -259,17 +187,56 @@ Yes - Are you sure delete this configuration? + Are you sure delete configuration '{0}'? Delete configuration + + Description + + + Id + + + Name + + + Publish time + + + Status + + + Version + + + Configuration detail + + + Description + + + Name + + + Secret + + + Select team + + + Add configuration + Create from Json Create from Text + + Edit configuration + Edit as Json @@ -282,6 +249,9 @@ Environment + + Add configuration + Delete @@ -300,6 +270,15 @@ Key + + Name + + + Status + + + Team + Value @@ -339,6 +318,15 @@ Publish configuration + + Secret + + + The system will encrypt the secret and can not be decrypted. You should keep the secret yourself. If you forget the origin secret, please reset it. + + + Reset secret + Start @@ -417,8 +405,8 @@ User name - - Apps + + Configurations Home @@ -585,4 +573,7 @@ User name + + Reset password + \ No newline at end of file diff --git a/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx b/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx index 199dd33..9bc2745 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx @@ -117,78 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 应用详情 - - - 应用代码 - - - 应用描述 - - - 应用名称 - - - 应用状态 - - - 团队 - - - 应用代码 - - - 应用描述 - - - 应用名称 - - - 访问密钥 - - - 选择所属团队 - - - 新增应用 - - - 编辑应用 - - - 新增 - - - 代码 - - - 应用Id - - - 名称 - - - 状态 - - - 团队 - - - 确定要删除应用 '{0}'? - - - 删除应用 - - - 访问密钥将被加密存储且无法解密,请自行保管。如果忘记密钥,请重新设置。 - - - 重置密钥 - - - 应用详情 - 应用配置 @@ -259,17 +187,41 @@ - 确定要删除配置吗? + 确定要删除配置'{0}'吗? 删除配置 + + Id + + + 配置详情 + + + 描述 + + + 名称 + + + 密钥 + + + 选择团队 + + + 新增配置 + 从Json创建 从文本创建 + + 编辑配置 + 编辑Json @@ -282,6 +234,9 @@ 应用环境 + + 新增配置 + 删除 @@ -300,6 +255,15 @@ + + 名称 + + + 状态 + + + 团队 + @@ -339,6 +303,15 @@ 发布配置 + + 密钥 + + + 访问密钥将被加密存储且无法解密,请自行保管。如果忘记密钥,请重新设置。 + + + 重置密钥 + 开始同步 @@ -417,8 +390,8 @@ 用户名 - - 应用 + + 配置 首页 @@ -585,4 +558,22 @@ 用户名 + + 重置密码 + + + 描述 + + + 名称 + + + 发布时间 + + + 状态 + + + 版本 + \ No newline at end of file diff --git a/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx b/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx index c4b9e04..7c06b55 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx @@ -117,78 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 應用詳情 - - - 應用代碼 - - - 應用描述 - - - 應用名稱 - - - 應用狀態 - - - 團隊 - - - 應用代碼 - - - 應用描述 - - - 應用名稱 - - - 訪問密鑰 - - - 選擇所屬團隊 - - - 新增應用 - - - 編輯應用 - - - 新增 - - - 代碼 - - - 應用Id - - - 姓名 - - - 狀態 - - - 團隊 - - - 確定要刪除此應用“{0}”嗎? - - - 刪除應用 - - - 存取密鑰將被加密儲存且無法解密,請自行保管。 如果忘記密鑰,請重新設定。 - - - 重置密鑰 - - - 應用詳情 - 應用配置 @@ -259,11 +187,14 @@ - 確定要刪除配置嗎? + 確定要刪除配置'{0}'嗎? 刪除配置 + + Id + 從Json創建 @@ -282,6 +213,9 @@ 應用環境 + + 新增配置 + 刪除 @@ -339,6 +273,15 @@ 發佈配置 + + 密鑰 + + + 存取密鑰將被加密儲存且無法解密,請自行保管。 如果忘記密鑰,請重新設定。 + + + 重置密鑰 + 開始同步 @@ -417,8 +360,8 @@ 用戶名 - - 應用 + + 配置 首頁 @@ -585,4 +528,52 @@ 用戶名 + + 重設密碼 + + + 描述 + + + 名稱 + + + 發佈時間 + + + 狀態 + + + 版本 + + + 配置詳情 + + + 描述 + + + 名稱 + + + 密鑰 + + + 選擇團隊 + + + 新增配置 + + + 編輯配置 + + + 名稱 + + + 狀態 + + + 團隊 + \ No newline at end of file diff --git a/Source/Starfish.Webapp/Rest/Defines/IAdministratorApi.cs b/Source/Starfish.Webapp/Rest/Defines/IAdministratorApi.cs new file mode 100644 index 0000000..5efa708 --- /dev/null +++ b/Source/Starfish.Webapp/Rest/Defines/IAdministratorApi.cs @@ -0,0 +1,19 @@ +using Nerosoft.Starfish.Transit; +using Refit; + +namespace Nerosoft.Starfish.Webapp.Rest; + +internal interface IAdministratorApi +{ + [Get("/api/administrator")] + Task>> QueryAsync([Query] AdministratorCriteria criteria, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); + + [Post("/api/administrator")] + Task AssignAsync([Body] AdministratorAssignDto data, CancellationToken cancellationToken = default); + + [Get("/api/administrator/count")] + Task> CountAsync([Query] AdministratorCriteria criteria, CancellationToken cancellationToken = default); + + [Delete("/api/administrator/{userId}")] + Task DeleteAsync(string userId, CancellationToken cancellationToken = default); +} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Rest/Defines/IAppsApi.cs b/Source/Starfish.Webapp/Rest/Defines/IAppsApi.cs deleted file mode 100644 index 175c887..0000000 --- a/Source/Starfish.Webapp/Rest/Defines/IAppsApi.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Nerosoft.Starfish.Transit; -using Refit; - -namespace Nerosoft.Starfish.Webapp.Rest; - -internal interface IAppsApi -{ - [Get("/api/apps")] - Task>> QueryAsync([Query] AppInfoCriteria criteria, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); - - [Get("/api/apps/count")] - Task> CountAsync([Query] AppInfoCriteria criteria, CancellationToken cancellationToken = default); - - [Get("/api/apps/{id}")] - Task> GetAsync(string id, CancellationToken cancellationToken = default); - - [Post("/api/apps")] - Task CreateAsync([Body] AppInfoCreateDto data, CancellationToken cancellationToken = default); - - [Put("/api/apps/{id}")] - Task UpdateAsync(string id, [Body] AppInfoUpdateDto data, CancellationToken cancellationToken = default); - - [Put("/api/apps/{id}/secret")] - Task SetSecretAsync(string id, [Body] AppInfoSetSecretDto data, CancellationToken cancellationToken = default); - - [Delete("/api/apps/{id}")] - Task DeleteAsync(string id, CancellationToken cancellationToken = default); - - [Put("/api/apps/{id}/{status}")] - Task ChangeStatusAsync(string id, string status, CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs index cbc7090..b879cfa 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -5,37 +5,49 @@ namespace Nerosoft.Starfish.Webapp.Rest; internal interface IConfigurationApi { - [Get("/api/apps/{id}/configuration/{environment}/item")] - [Headers("x-format: application/json")] - Task>> GetItemListAsync(string id, string environment, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); + [Get("/api/configuration")] + Task>> QueryAsync([Query] ConfigurationCriteria criteria, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); + + [Post("/api/configuration")] + Task CreateAsync(string teamId, [Body] ConfigurationEditDto data, CancellationToken cancellationToken = default); + + [Get("/api/configuration/count")] + Task> CountAsync([Query] ConfigurationCriteria criteria, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/item/count")] - Task> GetItemCountAsync(string id, string environment, CancellationToken cancellationToken = default); + [Get("/api/configuration/{id}")] + Task> GetAsync(string id, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/item")] - Task> GetItemsAsync(string id, string environment, [Header("x-format")] string format, CancellationToken cancellationToken = default); + [Put("/api/configuration/{id}")] + Task UpdateAsync(string id, [Body] ConfigurationEditDto data, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/detail")] - Task> GetAsync(string id, string environment, CancellationToken cancellationToken = default); + [Delete("/api/configuration/{id}")] + Task DeleteAsync(string id, CancellationToken cancellationToken = default); - [Post("/api/apps/{id}/configuration/{environment}")] - Task CreateAsync(string id, string environment, [Header("x-format")] string format, [Body] ConfigurationEditDto data, CancellationToken cancellationToken = default); + [Put("/api/configuration/{id}/secret")] + Task SetSecretAsync(string id, [Body] ConfigurationSecretSetRequestDto data, CancellationToken cancellationToken = default); - [Put("/api/apps/{id}/configuration/{environment}")] - Task UpdateAsync(string id, string environment, [Header("x-format")] string format, [Body] ConfigurationEditDto data, CancellationToken cancellationToken = default); + [Put("/api/Configuration/{id}/{availability}")] + Task ChangeStatusAsync(string id, string availability, CancellationToken cancellationToken = default); - [Delete("/api/apps/{id}/configuration/{environment}")] - Task DeleteAsync(string id, string environment, CancellationToken cancellationToken = default); + [Post("/api/configuration/{id}/publish")] + Task PublishAsync(string id, [Body] ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default); + + [Post("/api/configuration/{id}/redis")] + Task PushRedisAsync(string id, [Body] ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default); + + [Get("/api/configuration/{id}/item")] + [Headers("x-format: application/json")] + Task>> GetItemListAsync(string id, string keyword, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); - [Put("/api/apps/{id}/configuration/{environment}/{key}")] - Task UpdateItemValueAsync(string id, string environment, string key, [Body] ConfigurationValueUpdateDto data, CancellationToken cancellationToken = default); + [Get("/api/configuration/{id}/item")] + Task> GetItemsAsync(string id, [Header("x-format")] string format, CancellationToken cancellationToken = default); - [Post("/api/apps/{id}/configuration/{environment}/publish")] - Task PublishAsync(string id, string environment, [Body] ConfigurationPublishDto data, CancellationToken cancellationToken = default); + [Get("/api/configuration/{id}/item/count")] + Task> GetItemCountAsync(string id, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/archive")] - Task> GetArchivedAsync(string id, string environment, CancellationToken cancellationToken = default); + [Put("/api/configuration/{id}/item/{key}")] + Task UpdateValueAsync(string id, string key, [Body] string data, CancellationToken cancellationToken = default); - [Post("/api/apps/{id}/configuration/{environment}/redis")] - Task PushRedisAsync(string id, string environment, [Body] PushRedisRequestDto data); + [Put("/api/configuration/{id}/item")] + Task UpdateItemsAsync(string id, [Body] ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Rest/ServiceCollectionExtensions.cs b/Source/Starfish.Webapp/Rest/ServiceCollectionExtensions.cs index 53c4ade..1aeb5a8 100644 --- a/Source/Starfish.Webapp/Rest/ServiceCollectionExtensions.cs +++ b/Source/Starfish.Webapp/Rest/ServiceCollectionExtensions.cs @@ -39,7 +39,7 @@ public static IServiceCollection AddHttpClientApi(this IServiceCollection servic .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)) .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)) .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)) - .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)) + .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)) .AddTransient(provider => provider.GetRestService(HTTP_CLIENT_NAME)); services.AddHttpClient(HTTP_CLIENT_NAME, (provider, client) =>