From e163c8a540492f73303e03bd59888825902d4e6e Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 00:11:55 +0800 Subject: [PATCH 01/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=92=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B1=9E=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Aggregates/Configuration.cs | 83 +++++++++++++++---- .../Domain/Aggregates/ConfigurationArchive.cs | 22 ++--- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 7d99561..e385419 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,43 @@ private Configuration() { Status = @event.NewStatus; }); + Register(@event => + { + Name = @event.NewName; + }); + Register(@event => + { + Secret = @event.Secret; + }); + } + + private Configuration(string teamId, string name) + : this() + { + TeamId = teamId; + Name = name; + Status = ConfigurationStatus.Pending; } /// - /// 应用Id + /// 团队Id /// - public string AppId { get; set; } + public string TeamId { get; set; } /// - /// 应用环境 + /// 配置名称 /// - public string Environment { get; set; } + public string Name { get; set; } + + /// + /// 配置描述 + /// + public string Description { get; set; } + + /// + /// 访问密钥 + /// + public string Secret { get; set; } /// /// 状态 @@ -67,18 +94,13 @@ 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, IDictionary items) { - var configuration = new Configuration - { - AppId = appId, - Environment = environment, - Status = ConfigurationStatus.Pending - }; + var configuration = new Configuration(teamId, name); configuration.AddOrUpdateItem(items); @@ -86,6 +108,37 @@ internal static Configuration Create(string appId, string environment, IDictiona return configuration; } + internal void SetName(string name) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + if (string.Equals(name, Name, StringComparison.OrdinalIgnoreCase)) + { + return; + } + + RaiseEvent(new ConfigurationNameChangedEvent(Name, name)); + } + + /// + /// 设置访问密钥 + /// + /// + /// 密钥不符合规则时引发异常 + internal void SetSecret(string secret) + { + ArgumentException.ThrowIfNullOrWhiteSpace(secret); + + if (!Regex.IsMatch(secret, Constants.RegexPattern.Secret)) + { + throw new BadRequestException(Resources.IDS_ERROR_APPINFO_SECRET_NOT_MATCHES_RULE); + } + + if (!string.IsNullOrEmpty(Id)) + { + RaiseEvent(new ConfigurationSecretChangedEvent(Cryptography.SHA.Encrypt(secret))); + } + } + internal void AddOrUpdateItem(IDictionary items) { if (Status == ConfigurationStatus.Disabled) 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; From 66f0cf4c19166d91487ac7591f654e77a3730d47 Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 00:30:36 +0800 Subject: [PATCH 02/26] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=86=E5=9F=9F?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Aggregates/Configuration.cs | 87 +++++++++++++------ .../Business/ConfigurationArchiveBusiness.cs | 43 --------- .../Business/ConfigurationGeneralBusiness.cs | 10 +-- .../Business/ConfigurationPublishBusiness.cs | 2 +- .../Business/ConfigurationRevisionBusiness.cs | 30 ------- .../Events/ConfigurationItemChangedEvent.cs | 7 ++ .../Events/ConfigurationNameChangedEvent.cs | 16 ++++ .../Events/ConfigurationPublishedEvent.cs | 7 ++ .../Events/ConfigurationSecretChangedEvent.cs | 13 +++ 9 files changed, 110 insertions(+), 105 deletions(-) delete mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationArchiveBusiness.cs delete mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationRevisionBusiness.cs create mode 100644 Source/Starfish.Service/Domain/Events/ConfigurationItemChangedEvent.cs create mode 100644 Source/Starfish.Service/Domain/Events/ConfigurationNameChangedEvent.cs create mode 100644 Source/Starfish.Service/Domain/Events/ConfigurationPublishedEvent.cs create mode 100644 Source/Starfish.Service/Domain/Events/ConfigurationSecretChangedEvent.cs diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index e385419..728fa08 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -24,6 +24,14 @@ private Configuration() { Secret = @event.Secret; }); + Register(_ => + { + SetStatus(ConfigurationStatus.Published); + }); + Register(_ => + { + SetStatus(ConfigurationStatus.Pending); + }); } private Configuration(string teamId, string name) @@ -102,7 +110,7 @@ internal static Configuration Create(string teamId, string name, IDictionary /// 设置访问密钥 /// @@ -126,6 +146,8 @@ internal void SetName(string name) /// 密钥不符合规则时引发异常 internal void SetSecret(string secret) { + EnsureStatus(); + ArgumentException.ThrowIfNullOrWhiteSpace(secret); if (!Regex.IsMatch(secret, Constants.RegexPattern.Secret)) @@ -139,12 +161,9 @@ internal void SetSecret(string secret) } } - internal void AddOrUpdateItem(IDictionary items) + internal void UpdateItem(IDictionary items) { - if (Status == ConfigurationStatus.Disabled) - { - throw new InvalidOperationException(Resources.IDS_ERROR_CONFIG_DISABLED); - } + EnsureStatus(); Items ??= []; Items.RemoveAll(t => !items.ContainsKey(t.Key)); @@ -162,15 +181,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 ??= []; @@ -181,28 +197,18 @@ internal void UpdateItem(string key, string value) throw new InvalidOperationException(string.Format(Resources.IDS_ERROR_CONFIG_KEY_NOT_EXISTS, key)); } - item.Value = value; - - Status = ConfigurationStatus.Pending; - } - - internal void SetStatus(ConfigurationStatus status) - { - if (Status == status) + if (string.Equals(item.Value, value)) { return; } - RaiseEvent(new ConfigurationStatusChangedEvent(Status, status)); + item.Value = value; + + RaiseEvent(new ConfigurationItemChangedEvent()); } - internal void CreateRevision(string version, string comment, string @operator) + private void CreateRevision(string version, string comment, string @operator) { - if (Items == null || Items.Count == 0) - { - return; - } - Revisions ??= []; if (Revisions.Any(t => string.Equals(t.Version, version, StringComparison.OrdinalIgnoreCase))) @@ -215,8 +221,37 @@ internal void CreateRevision(string version, string comment, string @operator) 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 Publish(string version, string comment, string @operator) + { + EnsureStatus(); + + if (Items == null || Items.Count == 0) + { + throw new InvalidOperationException("配置项为空"); + } + + CreateArchive(@operator); + CreateRevision(version, comment, @operator); Version = version; PublishTime = DateTime.Now; + RaiseEvent(new ConfigurationPublishedEvent()); + } + + private void EnsureStatus() + { + if (Status == ConfigurationStatus.Disabled) + { + throw new ConfigurationDisabledException(Id); + } } } \ 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..40ad0cc 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs @@ -15,14 +15,14 @@ internal class ConfigurationGeneralBusiness : EditableObjectBase IdProperty = RegisterProperty(p => p.Id); + 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 long Id + public string Id { get => ReadProperty(IdProperty); set => LoadProperty(IdProperty, value); @@ -79,8 +79,8 @@ protected async Task FetchAsync(string appId, string environment, CancellationTo using (BypassRuleChecks) { Id = aggregate.Id; - AppId = aggregate.AppId; - Environment = aggregate.Environment; + AppId = aggregate.TeamId; + Environment = aggregate.Name; } } @@ -140,7 +140,7 @@ protected override async Task UpdateAsync(CancellationToken cancellationToken = if (ChangedProperties.Contains(ItemsProperty)) { - Aggregate.AddOrUpdateItem(Items); + Aggregate.UpdateItem(Items); } else if (ChangedProperties.Contains(KeyProperty) && ChangedProperties.Contains(ValueProperty)) { diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs index b34b51c..09a4afa 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs @@ -46,7 +46,7 @@ protected async Task ExecuteAsync(string appId, string environment, Cancellation if (aggregate.Status == ConfigurationStatus.Disabled) { - throw new ConfigurationDisabledException(appId, environment); + throw new ConfigurationDisabledException(appId); } aggregate.SetStatus(ConfigurationStatus.Published); 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/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 From 5e19b9269e8091bf6d1016ecc189549a6e823b5c Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 00:41:19 +0800 Subject: [PATCH 03/26] =?UTF-8?q?=E5=9B=A2=E9=98=9Frepository=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=88=90=E5=91=98=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Repositories/ITeamRepository.cs | 2 ++ .../Repository/Repositories/TeamRepository.cs | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs b/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs index b9a7df1..ddd3aaf 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/Repository/Repositories/TeamRepository.cs b/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs index 93f900c..889b53b 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 0; + } + + return user.IsOwner ? 1 : 2; + } } \ No newline at end of file From b0099c759e9e2b5420ad4f066af91552ef84dac3 Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 01:12:15 +0800 Subject: [PATCH 04/26] =?UTF-8?q?=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Common/PermissionState.cs | 8 ++++++++ .../Domain/Repositories/ITeamRepository.cs | 2 +- .../Repository/Repositories/TeamRepository.cs | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 Source/Starfish.Common/PermissionState.cs 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/Domain/Repositories/ITeamRepository.cs b/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs index ddd3aaf..24bd400 100644 --- a/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs +++ b/Source/Starfish.Service/Domain/Repositories/ITeamRepository.cs @@ -15,5 +15,5 @@ public interface ITeamRepository : IBaseRepository Task> GetMembersAsync(string id, CancellationToken cancellationToken = default); - Task CheckPermissionAsync(string id, string userId, CancellationToken cancellationToken = default); + Task CheckPermissionAsync(string id, string userId, CancellationToken cancellationToken = default); } \ 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 889b53b..e6b5904 100644 --- a/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs +++ b/Source/Starfish.Service/Repository/Repositories/TeamRepository.cs @@ -31,7 +31,7 @@ public Task> GetMembersAsync(string id, CancellationToken cance return query.ToListAsync(cancellationToken); } - public async Task CheckPermissionAsync(string id, string userId, CancellationToken cancellationToken = default) + 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 @@ -47,9 +47,9 @@ join member in Context.Set() on team.Id equals member.TeamId var user = result.FirstOrDefault(x => x.UserId == userId); if (user == null) { - return 0; + return PermissionState.None; } - return user.IsOwner ? 1 : 2; + return user.IsOwner ? PermissionState.Edit : PermissionState.Read; } } \ No newline at end of file From 54e40e5c4bc6bd060b860d2a8ba5ea5a588324f1 Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 01:13:41 +0800 Subject: [PATCH 05/26] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Aggregates/Configuration.cs | 32 ++++- .../Business/ConfigurationGeneralBusiness.cs | 115 ++++++++---------- .../Business/ConfigurationItemsBusiness.cs | 43 +++++++ .../Business/ConfigurationPublishBusiness.cs | 43 +++---- .../Business/ConfigurationSecretBusiness.cs | 43 +++++++ .../Business/ConfigurationStatusBusiness.cs | 50 ++++++++ .../Business/ConfigurationValueBusiness.cs | 43 +++++++ .../ConfigurationDisabledException.cs | 4 +- .../ConfigurationNotFoundException.cs | 13 +- 9 files changed, 289 insertions(+), 97 deletions(-) create mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs create mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationSecretBusiness.cs create mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationStatusBusiness.cs create mode 100644 Source/Starfish.Service/Domain/Business/ConfigurationValueBusiness.cs diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 728fa08..1913cb2 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -106,12 +106,9 @@ private Configuration(string teamId, string name) /// public ConfigurationArchive Archive { get; set; } - internal static Configuration Create(string teamId, string name, IDictionary items) + internal static Configuration Create(string teamId, string name) { var configuration = new Configuration(teamId, name); - - configuration.UpdateItem(items); - configuration.RaiseEvent(new ConfigurationCreatedEvent(configuration)); return configuration; } @@ -129,7 +126,7 @@ internal void SetName(string name) RaiseEvent(new ConfigurationNameChangedEvent(Name, name)); } - internal void SetStatus(ConfigurationStatus status) + private void SetStatus(ConfigurationStatus status) { if (Status == status) { @@ -254,4 +251,29 @@ private void EnsureStatus() throw new ConfigurationDisabledException(Id); } } + + internal void Disable() + { + if (Status == ConfigurationStatus.Disabled) + { + return; + } + + SetStatus(ConfigurationStatus.Disabled); + } + + internal void Enable() + { + if (Status != ConfigurationStatus.Disabled) + { + return; + } + + SetStatus(ConfigurationStatus.Pending); + } + + internal void SetDescription(string description) + { + Description = description; + } } \ 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 40ad0cc..b5b7750 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs @@ -8,7 +8,7 @@ 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; } @@ -16,11 +16,10 @@ internal class ConfigurationGeneralBusiness : EditableObjectBase 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 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 string Id { @@ -28,34 +27,28 @@ public string Id 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.TeamId; - Environment = aggregate.Name; + 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,13 +122,19 @@ protected override async Task UpdateAsync(CancellationToken cancellationToken = return; } - if (ChangedProperties.Contains(ItemsProperty)) + if (ChangedProperties.Contains(NameProperty)) { - Aggregate.UpdateItem(Items); + Aggregate.SetName(Name); } - else if (ChangedProperties.Contains(KeyProperty) && ChangedProperties.Contains(ValueProperty)) + + if (ChangedProperties.Contains(SecretProperty)) { - Aggregate.UpdateItem(Key, Value); + Aggregate.SetSecret(Secret); + } + + if (ChangedProperties.Contains(DescriptionProperty)) + { + Aggregate.SetDescription(Description); } await ConfigurationRepository.UpdateAsync(Aggregate, true, cancellationToken); @@ -153,15 +143,16 @@ protected override async Task UpdateAsync(CancellationToken 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 +171,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..d41907c --- /dev/null +++ b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs @@ -0,0 +1,43 @@ +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(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(items); + + 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 09a4afa..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); + 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/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/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..c38924a 100644 --- a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs +++ b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs @@ -5,13 +5,18 @@ /// public class ConfigurationNotFoundException : NotFoundException { + public ConfigurationNotFoundException(string id) + : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, id)) + { + } + /// /// 构造函数 /// - /// 应用Id - /// 应用环境 - public ConfigurationNotFoundException(string appId, string environment) - : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, appId, environment)) + /// 团队Id + /// 配置名称 + public ConfigurationNotFoundException(string teamId, string name) + : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, teamId, name)) { } } \ No newline at end of file From 0cd089bfc590791526ef9d181f31de91954e6d69 Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Feb 2024 01:14:19 +0800 Subject: [PATCH 06/26] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CommandObjectBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Seedwork/CommandObjectBase.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Source/Starfish.Service/Seedwork/CommandObjectBase.cs 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 From 15ea2338276bc577fc2be8e678fce05dcbfe31a5 Mon Sep 17 00:00:00 2001 From: damon Date: Fri, 16 Feb 2024 16:16:32 +0800 Subject: [PATCH 07/26] =?UTF-8?q?[WIP]=E6=8E=A5=E5=8F=A3=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configs/ConfigurationAbstractCommand.cs | 22 --- .../ConfigurationArchiveCreateCommand.cs | 19 -- .../Configs/ConfigurationCreateCommand.cs | 24 +-- .../Configs/ConfigurationDeleteCommand.cs | 15 +- .../ConfigurationItemsUpdateCommand.cs | 19 ++ .../Configs/ConfigurationPublishCommand.cs | 18 +- .../ConfigurationRevisionCreateCommand.cs | 24 --- .../Configs/ConfigurationUpdateCommand.cs | 20 +- .../ConfigurationValueUpdateCommand.cs | 14 +- .../Application/ConnectionContainer.cs | 5 +- .../IConfigurationApplicationService.cs | 68 +++---- .../Events/ConfigurationPublishedEvent.cs | 42 ----- .../Handlers/ConfigurationCommandHandler.cs | 50 +++-- .../ConfigurationApplicationService.cs | 68 ++++--- .../Mappings/ConfigurationMappingProfile.cs | 5 +- .../ConfigurationArchiveEventSubscriber.cs | 35 ---- .../ConfigurationRevisionEventSubscriber.cs | 34 ---- .../Subscribers/LoggingEventSubscriber.cs | 9 +- .../Domain/Aggregates/ConfigurationItem.cs | 2 +- .../Business/ConfigurationItemsBusiness.cs | 29 +++ .../IConfigurationArchiveRepository.cs | 4 +- .../Repositories/IConfigurationRepository.cs | 14 +- .../RelationalDatabaseModelBuilder.cs | 121 ++++++------ .../Repository/CriteriaExtensions.cs | 18 +- .../ConfigurationArchiveRepository.cs | 13 +- .../Repositories/ConfigurationRepository.cs | 50 +---- .../ConfigurationArchiveSpecification.cs | 10 +- .../ConfigurationSpecification.cs | 36 ++-- .../Configs/ConfigurationCountUseCase.cs | 34 ++++ .../Configs/ConfigurationCreateUseCase.cs | 33 +--- .../Configs/ConfigurationDeleteUseCase.cs | 7 +- .../ConfigurationItemsUpdateUseCase.cs | 44 +++++ .../Configs/ConfigurationPublishUseCase.cs | 14 +- .../Configs/ConfigurationQueryUseCase.cs | 35 ++++ .../Configs/ConfigurationUpdateUseCase.cs | 27 +-- .../ConfigurationValueUpdateUseCase.cs | 4 +- .../Configs/GetConfigurationArchiveUseCase.cs | 35 ++++ .../Configs/GetConfigurationDetailUseCase.cs | 18 +- .../GetConfigurationItemCountUseCase.cs | 7 +- .../GetConfigurationItemListUseCase.cs | 4 +- .../Configs/GetConfigurationRawUseCase.cs | 26 --- .../UseCases/Configs/PushRedisUseCase.cs | 25 ++- .../Configs/ConfigurationCriteria.cs | 8 +- ...rationDetailDto.cs => ConfigurationDto.cs} | 25 ++- .../Configs/ConfigurationEditDto.cs | 16 +- .../Configs/ConfigurationValueUpdateDto.cs | 12 -- .../Controllers/ConfigurationController.cs | 173 +++++++++--------- .../Starfish.Webapp/Pages/Configs/Index.razor | 22 +-- .../Rest/Defines/IConfigurationApi.cs | 2 +- 49 files changed, 671 insertions(+), 688 deletions(-) delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationAbstractCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationArchiveCreateCommand.cs create mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationRevisionCreateCommand.cs delete mode 100644 Source/Starfish.Service/Application/Events/ConfigurationPublishedEvent.cs delete mode 100644 Source/Starfish.Service/Application/Subscribers/ConfigurationArchiveEventSubscriber.cs delete mode 100644 Source/Starfish.Service/Application/Subscribers/ConfigurationRevisionEventSubscriber.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Configs/GetConfigurationRawUseCase.cs rename Source/Starfish.Transit/Configs/{ConfigurationDetailDto.cs => ConfigurationDto.cs} (62%) delete mode 100644 Source/Starfish.Transit/Configs/ConfigurationValueUpdateDto.cs 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/ConfigurationItemsUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs new file mode 100644 index 0000000..9f6c187 --- /dev/null +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs @@ -0,0 +1,19 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; + +public sealed class ConfigurationItemsUpdateCommand : Command +{ + public ConfigurationItemsUpdateCommand(string id, IDictionary items) + { + Id = id; + Items = items; + } + + public string Id { 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/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..f486f9b 100644 --- a/Source/Starfish.Service/Application/ConnectionContainer.cs +++ b/Source/Starfish.Service/Application/ConnectionContainer.cs @@ -22,7 +22,7 @@ public ConnectionContainer(IConfigurationApplicationService service) private async void OnClientConnected(object sender, ClientConnectedEventArgs e) { - var raw = await _service.GetArchiveAsync(e.AppId, e.Environment); + var raw = await _service.GetArchiveAsync(e.AppId); var key = $"{e.AppId}-{e.Environment}"; if (_connections.TryGetValue(key, out var connection)) { @@ -64,8 +64,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); } diff --git a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs index 922c521..72bf112 100644 --- a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs @@ -8,105 +8,107 @@ 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, int skip, int count, CancellationToken cancellationToken = default); /// /// 获取配置项数量 /// - /// - /// + /// /// /// - Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, 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 appId, string environment, CancellationToken cancellationToken = default); + Task DeleteAsync(string id, 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, string format, string data, CancellationToken cancellationToken = default); /// /// 发布配置 /// - /// - /// + /// /// /// /// - Task PublishAsync(string appId, string environment, ConfigurationPublishDto data, CancellationToken cancellationToken = default); + Task PublishAsync(string id, ConfigurationPublishDto 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, PushRedisRequestDto 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/ConfigurationCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs index 5dd25d4..0add601 100644 --- a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs +++ b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs @@ -10,13 +10,12 @@ namespace Nerosoft.Starfish.Application; /// 应用配置命令处理器 /// public class ConfigurationCommandHandler : CommandHandlerBase, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler, - IHandler + IHandler, + IHandler, + IHandler, + IHandler, + IHandler, + IHandler { public ConfigurationCommandHandler(IUnitOfWorkManager unitOfWork, IObjectFactory factory) : base(unitOfWork, factory) @@ -28,10 +27,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 +42,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 +55,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,7 +66,7 @@ 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); }); } @@ -70,27 +74,15 @@ public Task HandleAsync(ConfigurationValueUpdateCommand message, MessageContext { 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); - }); - } - - public Task HandleAsync(ConfigurationRevisionCreateCommand 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, message.Key, message.Value, cancellationToken); }); } - public Task HandleAsync(ConfigurationArchiveCreateCommand message, MessageContext context, CancellationToken cancellationToken = default) + public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext context, CancellationToken cancellationToken = new CancellationToken()) { return ExecuteAsync(async () => { - await Factory.ExecuteAsync(message.AppId, message.Environment, context.User?.Identity?.Name, cancellationToken); + await Factory.ExecuteAsync(message.Id, message.Items, 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..9a2736b 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -9,89 +9,109 @@ 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 ConfigurationQueryInput(criteria, skip, count); + return useCase.ExecuteAsync(input, cancellationToken) + .ContinueWith(t => t.Result.Result, cancellationToken); + } + + public Task CountAsync(ConfigurationCriteria criteria, CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + /// - public Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default) + public Task> GetItemListAsync(string id, int skip, int count, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationItemListInput(appId, environment, skip, count); + var input = new GetConfigurationItemListInput(id, 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, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationItemCountInput(appId, environment); + var input = new GetConfigurationItemCountInput(id); 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 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, string format, string data, CancellationToken cancellationToken = default) + { + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationItemsUpdateInput(id, format, data); return useCase.ExecuteAsync(input, cancellationToken); } /// - public Task PublishAsync(string appId, string environment, ConfigurationPublishDto data, CancellationToken cancellationToken = default) + public Task PublishAsync(string id, ConfigurationPublishDto 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, 0, int.MaxValue, cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); @@ -101,10 +121,10 @@ public Task GetItemsInTextAsync(string appId, string environment, string }, cancellationToken); } - public Task PushRedisAsync(string appId, string environment, PushRedisRequestDto data, CancellationToken cancellationToken = default) - { + public Task PushRedisAsync(string id, PushRedisRequestDto data, CancellationToken cancellationToken = default) + { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new PushRedisInput(appId, environment, data); + var input = new PushRedisInput(id, data); return useCase.ExecuteAsync(input, cancellationToken); } } \ 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..45d4f8c 100644 --- a/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs +++ b/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs @@ -13,9 +13,8 @@ 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))); } private static string GetStatusDescription(ConfigurationStatus status) 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..8d7982b 100644 --- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs +++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs @@ -191,7 +191,7 @@ 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 { @@ -216,7 +216,7 @@ 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 { @@ -233,7 +233,8 @@ public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context [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 { @@ -246,6 +247,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/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/Business/ConfigurationItemsBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs index d41907c..c270afa 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs @@ -40,4 +40,33 @@ protected async Task ExecuteAsync(string id, IDictionary 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/Repositories/IConfigurationArchiveRepository.cs b/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs index 66374f0..ce9e108 100644 --- a/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs +++ b/Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs @@ -3,7 +3,7 @@ namespace Nerosoft.Starfish.Domain; -public interface IConfigurationArchiveRepository : IBaseRepository +public interface IConfigurationArchiveRepository : IBaseRepository { - Task GetAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetAsync(string teamId, string name, 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..8a6f8c1 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, int skip, int count, CancellationToken cancellationToken = default); - Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs index 06d6bd0..e94fc39 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,19 +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); + .WithMany() + .HasForeignKey(t => t.UserId); }); } @@ -108,8 +108,8 @@ protected override ModelBuilder ConfigureApplication(ModelBuilder modelBuilder) entity.HasIndex(t => t.Status).HasDatabaseName("IDX_APP_INFO_TEAM_ID"); entity.Property(t => t.Id) - .IsRequired() - .HasValueGenerator(); + .IsRequired() + .HasValueGenerator(); }); } @@ -121,30 +121,26 @@ 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); }); } @@ -158,16 +154,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 +175,12 @@ 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(); + + entity.HasOne(t => t.Configuration) + .WithOne(t => t.Archive) + .HasForeignKey(nameof(ConfigurationArchive.Id)); }); } @@ -200,13 +195,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 +217,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 +235,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..fd1c4df 100644 --- a/Source/Starfish.Service/Repository/CriteriaExtensions.cs +++ b/Source/Starfish.Service/Repository/CriteriaExtensions.cs @@ -99,9 +99,23 @@ public static Specification GetSpecification(this ConfigurationCr return specification; } - if (!string.IsNullOrWhiteSpace(criteria.Environment)) + if (!string.IsNullOrWhiteSpace(criteria.TeamId)) { - specification &= ConfigurationSpecification.EnvironmentEquals(criteria.Environment); + specification &= ConfigurationSpecification.TeamIdEquals(criteria.TeamId); + } + + if (!string.IsNullOrWhiteSpace(criteria.Keyword)) + { + specification &= ConfigurationSpecification.Matches(criteria.Keyword); + } + + if (criteria.Status > 0) + { + 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/ConfigurationArchiveRepository.cs b/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs index 96250df..c42106b 100644 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs +++ b/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs @@ -1,29 +1,30 @@ -using Nerosoft.Euonia.Linq; +using Microsoft.EntityFrameworkCore; +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 class ConfigurationArchiveRepository : BaseRepository, IConfigurationArchiveRepository { public ConfigurationArchiveRepository(IContextProvider provider) : base(provider) { } - public Task GetAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetAsync(string teamId, string name, CancellationToken cancellationToken = default) { ISpecification[] specs = [ - ConfigurationArchiveSpecification.AppIdEquals(appId), - ConfigurationArchiveSpecification.EnvironmentEquals(environment) + ConfigurationArchiveSpecification.TeamIdEquals(teamId), + ConfigurationArchiveSpecification.NameEquals(name) ]; var specification = new CompositeSpecification(PredicateOperator.AndAlso, specs); var predicate = specification.Satisfy(); - return GetAsync(predicate, true, cancellationToken); + return GetAsync(predicate, query => query.Include(t => t.Configuration), 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..ee90a80 100644 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs +++ b/Source/Starfish.Service/Repository/Repositories/ConfigurationRepository.cs @@ -6,70 +6,40 @@ 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, 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); - } - - public Task> GetItemListAsync(string appId, string environment, int skip, int count, CancellationToken cancellationToken = default) - { - ISpecification[] specifications = - [ - ConfigurationSpecification.ConfigurationAppIdEquals(appId), - ConfigurationSpecification.ConfigurationAppEnvironmentEquals(environment) - ]; - - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); - var query = Context.Set() .AsQueryable() - .Include(t => t.Configuration); - return query.Where(predicate) + .AsNoTracking(); + return query.Where(t => t.ConfigurationId == id) .Skip(skip) .Take(count) .ToListAsync(cancellationToken); } - public Task GetItemCountAsync(string appId, string environment, CancellationToken cancellationToken = default) + public Task GetItemCountAsync(string id, CancellationToken cancellationToken = default) { - ISpecification[] specifications = - [ - ConfigurationSpecification.ConfigurationAppIdEquals(appId), - ConfigurationSpecification.ConfigurationAppEnvironmentEquals(environment) - ]; - - var predicate = new CompositeSpecification(PredicateOperator.AndAlso, specifications).Satisfy(); - var query = Context.Set() - .AsQueryable() - .Include(t => t.Configuration); - return query.Where(predicate).CountAsync(cancellationToken); + .AsQueryable(); + return query.Where(t => t.ConfigurationId == id).CountAsync(cancellationToken); } } \ 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/UseCases/Configs/ConfigurationCountUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs new file mode 100644 index 0000000..ed45d71 --- /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 = new CancellationToken()) + { + 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..27553ba 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; +public interface IConfigurationCreateUseCase : IUseCase; -public record ConfigurationCreateInput(string AppId, string Environment, string Format, ConfigurationEditDto Data) : IUseCaseInput; +public record ConfigurationCreateInput(string TeamId, ConfigurationEditDto Data) : IUseCaseInput; public 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..84a561d 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs @@ -12,9 +12,8 @@ public interface IConfigurationDeleteUseCase : INonOutputUseCase /// 删除配置节点输入 /// -/// -/// -public record ConfigurationDeleteInput(string AppId, string Environment) : IUseCaseInput; +/// +public record ConfigurationDeleteInput(string Id) : IUseCaseInput; /// /// 删除配置节点用例 @@ -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/ConfigurationItemsUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs new file mode 100644 index 0000000..bdfda1b --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs @@ -0,0 +1,44 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Euonia.Bus; +using Nerosoft.Starfish.Application; + +namespace Nerosoft.Starfish.UseCases; + +public interface IConfigurationItemsUpdateUseCase : INonOutputUseCase; + +public record ConfigurationItemsUpdateInput(string Id, string Format, string Data); + +public 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.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); + var command = new ConfigurationItemsUpdateCommand(input.Id, 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..e3c329f 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs @@ -13,10 +13,9 @@ public interface IConfigurationPublishUseCase : INonOutputUseCase /// 配置节点发布输入 /// -/// -/// +/// /// -public record ConfigurationPublishInput(string AppId, string Environment, ConfigurationPublishDto Data) : IUseCaseInput; +public record ConfigurationPublishInput(string Id, ConfigurationPublishDto Data) : IUseCaseInput; /// /// 配置节点发布用例 @@ -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/ConfigurationQueryUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs new file mode 100644 index 0000000..110431a --- /dev/null +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs @@ -0,0 +1,35 @@ +using Nerosoft.Euonia.Application; +using Nerosoft.Starfish.Domain; +using Nerosoft.Starfish.Repository; +using Nerosoft.Starfish.Transit; + +namespace Nerosoft.Starfish.UseCases; + +internal interface IConfigurationQueryUseCase : IUseCase; + +internal record ConfigurationQueryInput(ConfigurationCriteria Criteria, int Skip, int Count) : IUseCaseInput; + +internal record ConfigurationQueryOutput(List Result) : IUseCaseOutput; + +internal class ConfigurationQueryUseCase : IConfigurationQueryUseCase +{ + private readonly IConfigurationRepository _repository; + + public ConfigurationQueryUseCase(IConfigurationRepository repository) + { + _repository = repository; + } + + public Task ExecuteAsync(ConfigurationQueryInput input, CancellationToken cancellationToken = new CancellationToken()) + { + 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..553d88a 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs @@ -1,5 +1,6 @@ using Nerosoft.Euonia.Application; using Nerosoft.Euonia.Bus; +using Nerosoft.Euonia.Mapping; using Nerosoft.Starfish.Application; using Nerosoft.Starfish.Transit; @@ -7,37 +8,23 @@ namespace Nerosoft.Starfish.UseCases; public interface IConfigurationUpdateUseCase : INonOutputUseCase; -public record ConfigurationUpdateInput(string AppId, string Environment, string Format, ConfigurationEditDto Data); +public record ConfigurationUpdateInput(string Id, ConfigurationEditDto Data); public 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..193a035 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs @@ -6,7 +6,7 @@ namespace Nerosoft.Starfish.UseCases; public interface IConfigurationValueUpdateUseCase : INonOutputUseCase; -public record ConfigurationValueUpdateInput(string AppId, string Environment, string Key, string Value) : IUseCaseInput; +public record ConfigurationValueUpdateInput(string Id, string Key, string Value) : IUseCaseInput; public class ConfigurationValueUpdateUseCase : IConfigurationValueUpdateUseCase { @@ -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..46a763d --- /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; + +public interface IGetConfigurationArchiveUseCase : IUseCase; + +public record GetConfigurationArchiveOutput(string Result) : IUseCaseOutput; + +public record GetConfigurationArchiveInput(string Id) : IUseCaseInput; + +public 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..ed4de7d 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs @@ -16,13 +16,13 @@ public interface IGetConfigurationDetailUseCase : IUseCase /// -public record GetConfigurationDetailOutput(ConfigurationDetailDto Result) : IUseCaseOutput; +public record GetConfigurationDetailOutput(ConfigurationDto Result) : IUseCaseOutput; /// /// 获取配置节点详情用例输入 /// -/// -public record GetConfigurationDetailInput(string AppId, string Environment) : IUseCaseInput; +/// +public record GetConfigurationDetailInput(string Id) : IUseCaseInput; /// /// 获取配置节点详情用例 @@ -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..f922e80 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs @@ -17,9 +17,8 @@ public record GetConfigurationItemCountOutput(int Result) : IUseCaseOutput; /// /// 获取符合条件的配置数量用例输入 /// -/// -/// -public record GetConfigurationItemCountInput(string AppId, string Environment) : IUseCaseInput; +/// +public record GetConfigurationItemCountInput(string Id) : IUseCaseInput; /// /// 获取符合条件的配置数量用例 @@ -40,7 +39,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, 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..2655401 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemListUseCase.cs @@ -24,7 +24,7 @@ public record GetConfigurationItemListOutput(List Result) /// /// /// -public record GetConfigurationItemListInput(string Id, string Environment, int Skip, int Count) : IUseCaseInput; +public record GetConfigurationItemListInput(string Id, int Skip, int Count) : IUseCaseInput; /// /// 获取符合条件的配置列表用例 @@ -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, 0, 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 index 555c7a3..7895242 100644 --- a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs @@ -9,15 +9,15 @@ namespace Nerosoft.Starfish.UseCases; internal interface IPushRedisUseCase : INonOutputUseCase; -internal record PushRedisInput(string AppId, string Environment, PushRedisRequestDto Data) : IUseCaseInput; +internal record PushRedisInput(string Id, PushRedisRequestDto Data) : IUseCaseInput; internal sealed class PushRedisUseCase : IPushRedisUseCase { - private readonly IConfigurationArchiveRepository _configurationRepository; + private readonly IConfigurationRepository _configurationRepository; private readonly IAppInfoRepository _appInfoRepository; private readonly UserPrincipal _identity; - public PushRedisUseCase(IConfigurationArchiveRepository configurationRepository, IAppInfoRepository appInfoRepository, UserPrincipal identity) + public PushRedisUseCase(IConfigurationRepository configurationRepository, IAppInfoRepository appInfoRepository, UserPrincipal identity) { _configurationRepository = configurationRepository; _appInfoRepository = appInfoRepository; @@ -26,30 +26,35 @@ public PushRedisUseCase(IConfigurationArchiveRepository configurationRepository, public async Task ExecuteAsync(PushRedisInput input, CancellationToken cancellationToken = default) { - var permission = await _appInfoRepository.CheckPermissionAsync(input.AppId, _identity.UserId, cancellationToken); + var permission = await _appInfoRepository.CheckPermissionAsync(input.Id, _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); + var configuration = await _configurationRepository.GetAsync(input.Id, false, [nameof(Configuration.Archive)], cancellationToken); - if (archive == null) + if (configuration == null) { - throw new ConfigurationNotFoundException(input.AppId, input.Environment); + throw new ConfigurationNotFoundException(input.Id); } - if (string.IsNullOrWhiteSpace(archive.Data)) + if (configuration.Archive == null) + { + throw new NotFoundException("Archive not found."); + } + + if (string.IsNullOrWhiteSpace(configuration.Archive.Data)) { throw new InvalidDataException(); } - var data = GzipHelper.DecompressFromBase64(archive.Data); + var data = GzipHelper.DecompressFromBase64(configuration.Archive.Data); var items = JsonSerializer.Deserialize>(data); - var connection = ConnectionMultiplexer.Connect(input.Data.ConnectionString); + var connection = await ConnectionMultiplexer.ConnectAsync(input.Data.ConnectionString); using (connection) { var entries = items.Select(t => new HashEntry(t.Key, t.Value)).ToArray(); 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/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/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index ab08c1f..0357be7 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] + [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,70 +97,105 @@ 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) + [HttpPost("{id}/publish")] + public async Task PublishAsync(string id, [FromBody] ConfigurationPublishDto data) { - key = HttpUtility.UrlDecode(key); - await _service.UpdateAsync(id, environment, key, data.Value, HttpContext.RequestAborted); + await _service.PublishAsync(id, data, HttpContext.RequestAborted); return Ok(); } /// - /// 发布配置 + /// 推送到Redis /// - /// 应用Id - /// 应用环境 + /// /// /// - [HttpPost("publish")] - public async Task PublishAsync(string id, string environment, [FromBody] ConfigurationPublishDto data) + [HttpPost("{id}/redis")] + public async Task PushRedisAsync(string id, [FromBody] PushRedisRequestDto data) { - await _service.PublishAsync(id, environment, data, HttpContext.RequestAborted); + await _service.PushRedisAsync(id, data, HttpContext.RequestAborted); return Ok(); } /// - /// 获取发布的配置 + /// 获取配置项列表 /// /// 应用Id - /// 应用环境 + /// + /// + /// /// - [HttpGet("archive")] - [Produces] - public async Task GetArchivedAsync(string id, string environment) + [HttpGet("{id}/item")] + [Produces(typeof(List))] + public async Task GetItemListAsync(string id, int skip = Constants.Query.Skip, int count = Constants.Query.Count, [FromHeader(Name = "x-format")] string format = null) { - var result = await _service.GetArchiveAsync(id, environment, HttpContext.RequestAborted); + 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, skip, count, HttpContext.RequestAborted); + return Ok(result); + } + } + + /// + /// 获取配置项数量 + /// + /// 应用Id + /// + [HttpGet("{id}/item/count")] + [Produces(typeof(int))] + public async Task GetItemCountAsync(string id) + { + var result = await _service.GetItemCountAsync(id, HttpContext.RequestAborted); return Ok(result); } /// - /// 推送到Redis + /// 更新配置项的值 + /// + /// 应用Id + /// 完整Key名称 + /// + /// + [HttpPut("{id}/item/{key}")] + 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, [FromHeader(Name = "x-format")] string format, [FromBody] string data) { - await _service.PushRedisAsync(id, environment, data, HttpContext.RequestAborted); + await _service.UpdateItemsAsync(id, format, data, HttpContext.RequestAborted); return Ok(); } } \ No newline at end of file diff --git a/Source/Starfish.Webapp/Pages/Configs/Index.razor b/Source/Starfish.Webapp/Pages/Configs/Index.razor index 3b9a05d..da09144 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Index.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Index.razor @@ -61,13 +61,13 @@ @AppDetail?.Description - @if (ConfigurationDetail != null) + @if (Configuration != 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) + @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_VERSION, Configuration?.Version ?? "--") + @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_PUBLISH_TIME, Configuration?.PublishTime) + @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_UPDATE_TIME, Configuration?.UpdateTime) } @@ -77,7 +77,7 @@ @(Resources.IDS_CONFIG_INDEX_BUTTON_SYNC_REDIS) @(Resources.IDS_CONFIG_INDEX_BUTTON_DELETE) - @if (ConfigurationDetail?.Status == "Pending") + @if (Configuration?.Status == "Pending") { @(Resources.IDS_CONFIG_INDEX_BUTTON_PUBLISH) } @@ -106,7 +106,7 @@ private int Total { get; set; } - private ConfigurationDetailDto ConfigurationDetail { get; set; } + private ConfigurationDto Configuration { get; set; } private AppInfoDetailDto AppDetail { get; set; } @@ -158,7 +158,7 @@ private Task LoadConfigurationDetailAsync(CancellationToken cancellationToken = default) { return ConfigurationApi.GetAsync(Id, Environment, cancellationToken) - .EnsureSuccess(result => ConfigurationDetail = result, cancellationToken) + .EnsureSuccess(result => Configuration = result, cancellationToken) .Guard(); } @@ -175,11 +175,11 @@ { Properties = new Dictionary { - ["mode"] = ConfigurationDetail == null ? "create" : "update", + ["mode"] = Configuration == 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 title = Configuration == 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; @@ -195,12 +195,12 @@ { Properties = new Dictionary { - ["mode"] = ConfigurationDetail == null ? "create" : "update", + ["mode"] = Configuration == 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 title = Configuration == 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 result = await dialog.Result; diff --git a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs index cbc7090..2db6279 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -16,7 +16,7 @@ internal interface IConfigurationApi Task> GetItemsAsync(string id, string environment, [Header("x-format")] string format, CancellationToken cancellationToken = default); [Get("/api/apps/{id}/configuration/{environment}/detail")] - Task> GetAsync(string id, string environment, CancellationToken cancellationToken = default); + Task> GetAsync(string id, string environment, 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); From a72d92bab1894bf2d55285bcd9e704be95e342b6 Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 18 Feb 2024 09:56:32 +0800 Subject: [PATCH 08/26] =?UTF-8?q?WebApi=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handlers/ConfigurationCommandHandler.cs | 2 +- .../ConfigurationApplicationService.cs | 5 +- .../Admins/AdministratorDeleteUseCase.cs | 2 +- .../Configs/ConfigurationCountUseCase.cs | 2 +- .../Configs/ConfigurationQueryUseCase.cs | 2 +- .../Controllers/AppsController.cs | 143 ------------------ .../Controllers/ConfigurationController.cs | 6 +- .../Rest/Defines/IConfigurationApi.cs | 52 ++++--- 8 files changed, 41 insertions(+), 173 deletions(-) delete mode 100644 Source/Starfish.Webapi/Controllers/AppsController.cs diff --git a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs index 0add601..88252fa 100644 --- a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs +++ b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs @@ -78,7 +78,7 @@ public Task HandleAsync(ConfigurationValueUpdateCommand message, MessageContext }); } - public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext context, CancellationToken cancellationToken = new CancellationToken()) + public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => { diff --git a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs index 9a2736b..22509f0 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -19,7 +19,10 @@ public Task> QueryAsync(ConfigurationCriteria criteria, i public Task CountAsync(ConfigurationCriteria criteria, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + var useCase = LazyServiceProvider.GetRequiredService(); + var input = new ConfigurationCountInput(criteria); + return useCase.ExecuteAsync(input, cancellationToken) + .ContinueWith(t => t.Result.Result, cancellationToken); } /// 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/Configs/ConfigurationCountUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs index ed45d71..56a9aa4 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationCountUseCase.cs @@ -20,7 +20,7 @@ public ConfigurationCountUseCase(IConfigurationRepository repository) _repository = repository; } - public Task ExecuteAsync(ConfigurationCountInput input, CancellationToken cancellationToken = new CancellationToken()) + public Task ExecuteAsync(ConfigurationCountInput input, CancellationToken cancellationToken = default) { var specification = input.Criteria.GetSpecification(); var predicate = specification.Satisfy(); diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs index 110431a..34acc1c 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs @@ -20,7 +20,7 @@ public ConfigurationQueryUseCase(IConfigurationRepository repository) _repository = repository; } - public Task ExecuteAsync(ConfigurationQueryInput input, CancellationToken cancellationToken = new CancellationToken()) + public Task ExecuteAsync(ConfigurationQueryInput input, CancellationToken cancellationToken = default) { var specification = input.Criteria.GetSpecification(); var predicate = specification.Satisfy(); 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 0357be7..b0f2293 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -45,7 +45,7 @@ public async Task QueryAsync([FromQuery] ConfigurationCriteria cr /// /// /// - [HttpGet("@count")] + [HttpGet("count")] [Produces(typeof(int))] public async Task CountAsync([FromQuery] ConfigurationCriteria criteria) { @@ -58,7 +58,7 @@ public async Task CountAsync([FromQuery] ConfigurationCriteria cr /// /// 应用Id /// - [HttpGet] + [HttpGet("{id}")] [Produces] public async Task GetAsync(string id) { @@ -178,6 +178,7 @@ public async Task GetItemCountAsync(string id) /// /// [HttpPut("{id}/item/{key}")] + [Consumes("text/plain")] public async Task UpdateValueAsync(string id, string key, [FromBody] string data) { key = HttpUtility.UrlDecode(key); @@ -193,6 +194,7 @@ public async Task UpdateValueAsync(string id, string key, [FromBo /// /// [HttpPut("{id}/item")] + [Consumes("text/plain")] public async Task UpdateItemsAsync(string id, [FromHeader(Name = "x-format")] string format, [FromBody] string data) { await _service.UpdateItemsAsync(id, format, data, HttpContext.RequestAborted); diff --git a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs index 2db6279..2244017 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -5,37 +5,43 @@ 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/apps/{id}/configuration/{environment}/item/count")] - Task> GetItemCountAsync(string id, string environment, CancellationToken cancellationToken = default); + [Get("/api/configuration/count")] + Task> CountAsync([Query] ConfigurationCriteria criteria, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/item")] - Task> GetItemsAsync(string id, string environment, [Header("x-format")] string format, CancellationToken cancellationToken = default); + [Get("/api/configuration/{id}")] + Task> GetAsync(string id, CancellationToken cancellationToken = default); - [Get("/api/apps/{id}/configuration/{environment}/detail")] - Task> GetAsync(string id, string environment, CancellationToken cancellationToken = default); + [Put("/api/configuration/{id}")] + Task UpdateAsync(string id, [Body] ConfigurationEditDto data, 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); + [Delete("/api/configuration/{id}")] + Task DeleteAsync(string id, 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); + [Post("/api/configuration/{id}/publish")] + Task PublishAsync(string id, [Body] ConfigurationPublishDto data, CancellationToken cancellationToken = default); - [Delete("/api/apps/{id}/configuration/{environment}")] - Task DeleteAsync(string id, string environment, CancellationToken cancellationToken = default); + [Post("/api/configuration/{id}/redis")] + Task PushRedisAsync(string id, [Body] PushRedisRequestDto data, CancellationToken cancellationToken = default); + + [Get("/api/configuration/{id}/item")] + [Headers("x-format: application/json")] + Task>> GetItemListAsync(string id, 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, [Header("x-format")] string format, [Body] string data, CancellationToken cancellationToken = default); } \ No newline at end of file From 81a206a3bbc033a0ce605a8d92c9c4b56be7d78b Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 18 Feb 2024 18:06:00 +0800 Subject: [PATCH 09/26] =?UTF-8?q?=E5=88=A0=E9=99=A4AppInfo=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=87=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Configs/AppInfoCreateCommand.cs | 19 -- .../Commands/Configs/AppInfoDeleteCommand.cs | 18 -- .../Configs/AppInfoSetSecretCommand.cs | 19 -- .../Commands/Configs/AppInfoUpdateCommand.cs | 20 --- .../Configs/ChangeAppStatusCommand.cs | 25 --- .../Contracts/IAppsApplicationService.cs | 95 ---------- .../Handlers/AppInfoCommandHandler.cs | 95 ---------- .../Implements/AppsApplicationService.cs | 97 ---------- .../Mappings/AppsMappingProfile.cs | 30 ---- .../Domain/Aggregates/AppInfo.cs | 165 ------------------ .../Domain/Business/AppInfoGeneralBusiness.cs | 132 -------------- .../Domain/Business/AppInfoSecretBusiness.cs | 37 ---- .../Domain/Business/AppInfoStatusBusiness.cs | 48 ----- .../Domain/Enums/AppStatus.cs | 26 --- .../Domain/Events/AppInfoCreatedEvent.cs | 10 -- .../Domain/Events/AppInfoDeletedEvent.cs | 10 -- .../Exceptions/AppInfoNotEnabledException.cs | 9 - .../Exceptions/AppInfoNotFoundException.cs | 16 -- .../InvalidAppInfoStatusException.cs | 17 -- .../Domain/Repositories/IAppInfoRepository.cs | 12 -- .../Repositories/AppInfoRepository.cs | 44 ----- .../Specifications/AppInfoSpecification.cs | 86 --------- .../UseCases/Apps/AppInfoAuthorizeUseCase.cs | 55 ------ .../UseCases/Apps/AppInfoCountUseCase.cs | 69 -------- .../UseCases/Apps/AppInfoCreateUseCase.cs | 52 ------ .../UseCases/Apps/AppInfoDeleteUseCase.cs | 54 ------ .../UseCases/Apps/AppInfoDetailUseCase.cs | 75 -------- .../UseCases/Apps/AppInfoQueryUseCase.cs | 117 ------------- .../UseCases/Apps/AppInfoSetSecretUseCase.cs | 25 --- .../UseCases/Apps/AppInfoUpdateUseCase.cs | 46 ----- .../Apps/ChangeAppInfoStatusUseCase.cs | 46 ----- .../Apps/AppInfoSetSecretDto.cs | 12 -- 32 files changed, 1581 deletions(-) delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/AppInfoCreateCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/AppInfoDeleteCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/AppInfoUpdateCommand.cs delete mode 100644 Source/Starfish.Service/Application/Commands/Configs/ChangeAppStatusCommand.cs delete mode 100644 Source/Starfish.Service/Application/Contracts/IAppsApplicationService.cs delete mode 100644 Source/Starfish.Service/Application/Handlers/AppInfoCommandHandler.cs delete mode 100644 Source/Starfish.Service/Application/Implements/AppsApplicationService.cs delete mode 100644 Source/Starfish.Service/Application/Mappings/AppsMappingProfile.cs delete mode 100644 Source/Starfish.Service/Domain/Aggregates/AppInfo.cs delete mode 100644 Source/Starfish.Service/Domain/Business/AppInfoGeneralBusiness.cs delete mode 100644 Source/Starfish.Service/Domain/Business/AppInfoSecretBusiness.cs delete mode 100644 Source/Starfish.Service/Domain/Business/AppInfoStatusBusiness.cs delete mode 100644 Source/Starfish.Service/Domain/Enums/AppStatus.cs delete mode 100644 Source/Starfish.Service/Domain/Events/AppInfoCreatedEvent.cs delete mode 100644 Source/Starfish.Service/Domain/Events/AppInfoDeletedEvent.cs delete mode 100644 Source/Starfish.Service/Domain/Exceptions/AppInfoNotEnabledException.cs delete mode 100644 Source/Starfish.Service/Domain/Exceptions/AppInfoNotFoundException.cs delete mode 100644 Source/Starfish.Service/Domain/Exceptions/InvalidAppInfoStatusException.cs delete mode 100644 Source/Starfish.Service/Domain/Repositories/IAppInfoRepository.cs delete mode 100644 Source/Starfish.Service/Repository/Repositories/AppInfoRepository.cs delete mode 100644 Source/Starfish.Service/Repository/Specifications/AppInfoSpecification.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoAuthorizeUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoCountUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoCreateUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoDeleteUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoDetailUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoQueryUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoSetSecretUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/AppInfoUpdateUseCase.cs delete mode 100644 Source/Starfish.Service/UseCases/Apps/ChangeAppInfoStatusUseCase.cs delete mode 100644 Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs 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/AppInfoSetSecretCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs deleted file mode 100644 index b70faac..0000000 --- a/Source/Starfish.Service/Application/Commands/Configs/AppInfoSetSecretCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Nerosoft.Euonia.Domain; - -namespace Nerosoft.Starfish.Application; - -/// -/// 设置App密钥命令 -/// -public class AppInfoSetSecretCommand : Command -{ - public AppInfoSetSecretCommand(string id, string secret) - { - Id = id; - Secret = secret; - } - - public string Id { get; set; } - - public string Secret { get; set; } -} \ 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/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/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/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/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/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/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/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/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/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/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/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/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.Transit/Apps/AppInfoSetSecretDto.cs b/Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs deleted file mode 100644 index 9c0ac9c..0000000 --- a/Source/Starfish.Transit/Apps/AppInfoSetSecretDto.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Nerosoft.Starfish.Transit; - -/// -/// 设置应用密钥Dto -/// -public class AppInfoSetSecretDto -{ - /// - /// 密钥 - /// - public string Secret { get; set; } -} \ No newline at end of file From eec81fbb5b3e837c2c5ea19b786305da197d3b2f Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 18 Feb 2024 21:50:05 +0800 Subject: [PATCH 10/26] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/ApplicationServiceModule.cs | 1 - .../Configs/ConfigurationDisableCommand.cs | 13 ++ .../Configs/ConfigurationEnableCommand.cs | 13 ++ .../Configs/ConfigurationSetSecretCommand.cs | 19 ++ .../Application/ConnectionContainer.cs | 26 +-- .../IConfigurationApplicationService.cs | 40 +++- .../Handlers/ConfigurationCommandHandler.cs | 34 ++- .../ConfigurationApplicationService.cs | 33 ++- .../Mappings/IdentityMappingProfile.cs | 5 + .../Domain/Aggregates/Configuration.cs | 2 +- .../ConfigurationNotFoundException.cs | 10 - .../IConfigurationArchiveRepository.cs | 9 - .../IConfigurationRevisionRepository.cs | 8 - .../Properties/Resources.resx | 155 ++++++++----- .../Properties/Resources.zh-Hans.resx | 147 +++++++----- .../Properties/Resources.zh-Hant.resx | 215 ++++++++++++------ .../Contexts/AbstractDatabaseModelBuilder.cs | 3 - .../RelationalDatabaseModelBuilder.cs | 16 -- .../Repository/CriteriaExtensions.cs | 35 --- .../ConfigurationArchiveRepository.cs | 30 --- .../ConfigurationRevisionRepository.cs | 13 -- .../Repository/RepositoryModule.cs | 5 +- .../Configs/ConfigurationAuthorizeUseCase.cs | 59 +++++ .../Configs/ConfigurationDisableUseCase.cs | 25 ++ .../Configs/ConfigurationEnableUseCase.cs | 25 ++ .../Configs/ConfigurationPublishUseCase.cs | 2 +- .../UseCases/Configs/PushRedisUseCase.cs | 8 +- .../Configs/SetConfigurationSecretUseCase.cs | 25 ++ ...o.cs => ConfigurationPublishRequestDto.cs} | 2 +- ...cs => ConfigurationPushRedisRequestDto.cs} | 2 +- .../ConfigurationSecretSetRequestDto.cs | 12 + .../Controllers/ConfigurationController.cs | 41 +++- .../Controllers/EventStreamController.cs | 24 +- .../Controllers/WebSocketController.cs | 21 +- 34 files changed, 708 insertions(+), 370 deletions(-) create mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationDisableCommand.cs create mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationEnableCommand.cs create mode 100644 Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs delete mode 100644 Source/Starfish.Service/Domain/Repositories/IConfigurationArchiveRepository.cs delete mode 100644 Source/Starfish.Service/Domain/Repositories/IConfigurationRevisionRepository.cs delete mode 100644 Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs delete mode 100644 Source/Starfish.Service/Repository/Repositories/ConfigurationRevisionRepository.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationDisableUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/ConfigurationEnableUseCase.cs create mode 100644 Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs rename Source/Starfish.Transit/Configs/{ConfigurationPublishDto.cs => ConfigurationPublishRequestDto.cs} (85%) rename Source/Starfish.Transit/Configs/{PushRedisRequestDto.cs => ConfigurationPushRedisRequestDto.cs} (89%) create mode 100644 Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs 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/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/ConfigurationSetSecretCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs new file mode 100644 index 0000000..380be73 --- /dev/null +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationSetSecretCommand.cs @@ -0,0 +1,19 @@ +using Nerosoft.Euonia.Domain; + +namespace Nerosoft.Starfish.Application; + +/// +/// 设置App密钥命令 +/// +public class ConfigurationSetSecretCommand : Command +{ + public ConfigurationSetSecretCommand(string id, string secret) + { + Id = id; + Secret = secret; + } + + public string Id { get; set; } + + public string Secret { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Application/ConnectionContainer.cs b/Source/Starfish.Service/Application/ConnectionContainer.cs index f486f9b..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); - 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 _); } } @@ -72,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/IConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs index 72bf112..e756e0d 100644 --- a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs @@ -64,6 +64,42 @@ public interface IConfigurationApplicationService : IApplicationService /// Task DeleteAsync(string id, CancellationToken cancellationToken = default); + /// + /// 设置访问密钥 + /// + /// + /// + /// + /// + Task SetSecretAsync(string id, string secret, 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); + /// /// 更新配置项 /// @@ -91,7 +127,7 @@ public interface IConfigurationApplicationService : IApplicationService /// /// /// - Task PublishAsync(string id, ConfigurationPublishDto data, CancellationToken cancellationToken = default); + Task PublishAsync(string id, ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default); /// /// 获取已发布的配置 @@ -110,5 +146,5 @@ public interface IConfigurationApplicationService : IApplicationService /// Task GetItemsInTextAsync(string id, string format, CancellationToken cancellationToken = default); - Task PushRedisAsync(string id, 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/Handlers/ConfigurationCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs index 88252fa..df1656b 100644 --- a/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs +++ b/Source/Starfish.Service/Application/Handlers/ConfigurationCommandHandler.cs @@ -15,7 +15,10 @@ public class ConfigurationCommandHandler : CommandHandlerBase, IHandler, IHandler, IHandler, - IHandler + IHandler, + IHandler, + IHandler, + IHandler { public ConfigurationCommandHandler(IUnitOfWorkManager unitOfWork, IObjectFactory factory) : base(unitOfWork, factory) @@ -70,6 +73,7 @@ public Task HandleAsync(ConfigurationPublishCommand message, MessageContext cont }); } + /// public Task HandleAsync(ConfigurationValueUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => @@ -78,6 +82,7 @@ public Task HandleAsync(ConfigurationValueUpdateCommand message, MessageContext }); } + /// public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default) { return ExecuteAsync(async () => @@ -85,4 +90,31 @@ public Task HandleAsync(ConfigurationItemsUpdateCommand message, MessageContext 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(ConfigurationDisableCommand message, MessageContext context, CancellationToken cancellationToken = default) + { + return ExecuteAsync(async () => + { + await Factory.ExecuteAsync(message.Id, false, cancellationToken); + }); + } + + /// + public Task HandleAsync(ConfigurationEnableCommand message, MessageContext context, CancellationToken cancellationToken = default) + { + return ExecuteAsync(async () => + { + await Factory.ExecuteAsync(message.Id, true, 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 22509f0..61d2c03 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -77,6 +77,35 @@ public Task DeleteAsync(string id, CancellationToken cancellationToken = default 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 UpdateValueAsync(string id, string key, string value, CancellationToken cancellationToken = default) { @@ -93,7 +122,7 @@ public Task UpdateItemsAsync(string id, string format, string data, Cancellation } /// - public Task PublishAsync(string id, ConfigurationPublishDto data, CancellationToken cancellationToken = default) + public Task PublishAsync(string id, ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); var input = new ConfigurationPublishInput(id, data); @@ -124,7 +153,7 @@ public Task GetItemsInTextAsync(string id, string format, CancellationTo }, cancellationToken); } - public Task PushRedisAsync(string id, PushRedisRequestDto data, CancellationToken cancellationToken = default) + public Task PushRedisAsync(string id, ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); var input = new PushRedisInput(id, data); 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/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 1913cb2..3a5ab79 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -149,7 +149,7 @@ internal void SetSecret(string secret) if (!Regex.IsMatch(secret, Constants.RegexPattern.Secret)) { - throw new BadRequestException(Resources.IDS_ERROR_APPINFO_SECRET_NOT_MATCHES_RULE); + throw new BadRequestException(Resources.IDS_ERROR_CONFIG_SECRET_NOT_MATCHES_RULE); } if (!string.IsNullOrEmpty(Id)) diff --git a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs index c38924a..c317fca 100644 --- a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs +++ b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs @@ -9,14 +9,4 @@ public ConfigurationNotFoundException(string id) : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, id)) { } - - /// - /// 构造函数 - /// - /// 团队Id - /// 配置名称 - public ConfigurationNotFoundException(string teamId, string name) - : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, teamId, name)) - { - } } \ 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 ce9e108..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 teamId, string name, 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/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index c0dda26..9373b52 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -1,17 +1,17 @@  - @@ -119,185 +119,230 @@ Development + Performance Evaluation Testing + Production + Simulation Testing + System Integration Testing + User Acceptance Testing + System administrator - - - Disabled - - - Enabled + Disabled + Pending + 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. + You are not authorized to operate. + Data format '{0}' is not supported. + 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. + Configuration key '{0}' not exists. + - Configuration not exists, [App]:{0}, [Env]:{1}. + Configuration not exists, [Id]:{0}. + No pending item to publish. + + + + The secret not matches rule. + + + + App secret is required. + + + + Invalid app status. + Version number '{0}' already exists. + The query parameter 'count' must be greater than 0. + The query parameter 'skip' can not be a negative number. + The password is not correct. + Refresh token is expired. + Refresh token is invalid. + Refresh_token is required. + Team not exists, [Id]:{0}. + The team owner can not be removed. + User id(s) require. + Unsupported cache provider '{0}'. + Unsupported database provider '{0}'. + Unsupported service bus provider '{0}'. + Email '{0}' not available. + The user was locked out. + Not allowed to change role for reserved user. + Not allowed to delete reserved user. + User not exists, [Id]:{0}. + The password must be 8-32 characters long, contain at least one uppercase letter, one lowercase letter. + Password is required. + Username or password is invalid. + 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. + 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}. + - Publish configuration, [App]:{0}, [Env]:{1}. + Publish configuration, [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..c6bab5f 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,230 @@ 开发环境 + 性能评估测试 + 生产环境 + 模拟测试 + 系统集成测试 + 用户验收测试 + 系统管理员 - - - 禁用 - - - 启用 + 禁用 + 待发布 + 已发布 - - - 应用没有启用,[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}。 + 删除配置,[应用]:{0},[环境]:{1}。 + 发布配置,[应用]:{0},[环境]:{1}。 + 更新配置,[应用]:{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..9291610 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,240 @@ 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},[環境]:{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}。 + 刪除設置,[應用程式]:{0},[環境]:{1}。 + 發佈設置,[應用程式]:{0},[環境]:{1}。 + 更新設置,[應用程式]:{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/RelationalDatabaseModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs index e94fc39..ac76a07 100644 --- a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs +++ b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs @@ -97,22 +97,6 @@ protected override ModelBuilder ConfigureTeamMember(ModelBuilder modelBuilder) }); } - 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(); - }); - } - protected override ModelBuilder ConfigureConfiguration(ModelBuilder modelBuilder) { return modelBuilder.Entity(entity => diff --git a/Source/Starfish.Service/Repository/CriteriaExtensions.cs b/Source/Starfish.Service/Repository/CriteriaExtensions.cs index fd1c4df..8be5e46 100644 --- a/Source/Starfish.Service/Repository/CriteriaExtensions.cs +++ b/Source/Starfish.Service/Repository/CriteriaExtensions.cs @@ -51,41 +51,6 @@ public static Specification GetSpecification(this OperateLogCriteria return specification; } - /// - /// 获取应用信息查询规约 - /// - /// - /// - public static Specification GetSpecification(this AppInfoCriteria criteria) - { - 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)) - { - specification &= AppInfoSpecification.TeamIdEquals(criteria.TeamId); - } - - if (!string.IsNullOrWhiteSpace(criteria.Keyword)) - { - specification &= AppInfoSpecification.NameContains(criteria.Keyword); - } - - return specification; - } - /// /// 获取配置节点查询规约 /// diff --git a/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs b/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs deleted file mode 100644 index c42106b..0000000 --- a/Source/Starfish.Service/Repository/Repositories/ConfigurationArchiveRepository.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore; -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 teamId, string name, CancellationToken cancellationToken = default) - { - ISpecification[] specs = - [ - ConfigurationArchiveSpecification.TeamIdEquals(teamId), - ConfigurationArchiveSpecification.NameEquals(name) - ]; - - var specification = new CompositeSpecification(PredicateOperator.AndAlso, specs); - - var predicate = specification.Satisfy(); - - return GetAsync(predicate, query => query.Include(t => t.Configuration), 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/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/UseCases/Configs/ConfigurationAuthorizeUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs new file mode 100644 index 0000000..c2f4a17 --- /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(string.Empty); + } + + 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/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/ConfigurationPublishUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs index e3c329f..01c6fb9 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs @@ -15,7 +15,7 @@ public interface IConfigurationPublishUseCase : INonOutputUseCase /// /// -public record ConfigurationPublishInput(string Id, ConfigurationPublishDto Data) : IUseCaseInput; +public record ConfigurationPublishInput(string Id, ConfigurationPublishRequestDto Data) : IUseCaseInput; /// /// 配置节点发布用例 diff --git a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs b/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs index 7895242..4941ec5 100644 --- a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs @@ -9,15 +9,15 @@ namespace Nerosoft.Starfish.UseCases; internal interface IPushRedisUseCase : INonOutputUseCase; -internal record PushRedisInput(string Id, PushRedisRequestDto Data) : IUseCaseInput; +internal record PushRedisInput(string Id, ConfigurationPushRedisRequestDto Data) : IUseCaseInput; internal sealed class PushRedisUseCase : IPushRedisUseCase { private readonly IConfigurationRepository _configurationRepository; - private readonly IAppInfoRepository _appInfoRepository; + private readonly ITeamRepository _appInfoRepository; private readonly UserPrincipal _identity; - public PushRedisUseCase(IConfigurationRepository configurationRepository, IAppInfoRepository appInfoRepository, UserPrincipal identity) + public PushRedisUseCase(IConfigurationRepository configurationRepository, ITeamRepository appInfoRepository, UserPrincipal identity) { _configurationRepository = configurationRepository; _appInfoRepository = appInfoRepository; @@ -28,7 +28,7 @@ public async Task ExecuteAsync(PushRedisInput input, CancellationToken cancellat { var permission = await _appInfoRepository.CheckPermissionAsync(input.Id, _identity.UserId, cancellationToken); - if (!permission.IsIn(1, 2)) + if (permission != PermissionState.Edit) { throw new UnauthorizedAccessException(Resources.IDS_ERROR_COMMON_UNAUTHORIZED_ACCESS); } diff --git a/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs b/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs new file mode 100644 index 0000000..4f03562 --- /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; + +public interface ISetConfigurationSecretUseCase : INonOutputUseCase; + +public record SetConfigurationSecretInput(string Id, string Secret) : IUseCaseInput; + +public 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.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/Configs/ConfigurationSecretSetRequestDto.cs b/Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs new file mode 100644 index 0000000..2082c74 --- /dev/null +++ b/Source/Starfish.Transit/Configs/ConfigurationSecretSetRequestDto.cs @@ -0,0 +1,12 @@ +namespace Nerosoft.Starfish.Transit; + +/// +/// 访问密钥设置请求 +/// +public class ConfigurationSecretSetRequestDto +{ + /// + /// 访问密钥 + /// + public string Secret { get; set; } +} \ No newline at end of file diff --git a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index b0f2293..a8df173 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -105,6 +105,43 @@ public async Task DeleteAsync(string id) return Ok(); } + /// + /// 设置访问密钥 + /// + /// + /// + /// + [HttpPatch("{id}/secret")] + public async Task SetSecretAsync(string id, [FromBody] ConfigurationSecretSetRequestDto data) + { + await _service.SetSecretAsync(id, data.Secret, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 禁用配置 + /// + /// + /// + [HttpPatch("{id}/disable")] + public async Task DisableAsync(string id) + { + await _service.DisableAsync(id, HttpContext.RequestAborted); + return Ok(); + } + + /// + /// 启用配置 + /// + /// + /// + [HttpPatch("{id}/enable")] + public async Task EnableAsync(string id) + { + await _service.EnableAsync(id, HttpContext.RequestAborted); + return Ok(); + } + /// /// 发布配置 /// @@ -112,7 +149,7 @@ public async Task DeleteAsync(string id) /// /// [HttpPost("{id}/publish")] - public async Task PublishAsync(string id, [FromBody] ConfigurationPublishDto data) + public async Task PublishAsync(string id, [FromBody] ConfigurationPublishRequestDto data) { await _service.PublishAsync(id, data, HttpContext.RequestAborted); return Ok(); @@ -125,7 +162,7 @@ public async Task PublishAsync(string id, [FromBody] Configuratio /// /// [HttpPost("{id}/redis")] - public async Task PushRedisAsync(string id, [FromBody] PushRedisRequestDto data) + public async Task PushRedisAsync(string id, [FromBody] ConfigurationPushRedisRequestDto data) { await _service.PushRedisAsync(id, data, HttpContext.RequestAborted); return Ok(); 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 From 0946585cfedf03612e6dd1b5ee07f4e4ffb5340b Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 18 Feb 2024 22:45:19 +0800 Subject: [PATCH 11/26] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfigurationApplicationService.cs | 4 +- .../Subscribers/LoggingEventSubscriber.cs | 98 +++++------- .../Domain/Aggregates/Configuration.cs | 45 +++--- .../Business/ConfigurationGeneralBusiness.cs | 2 + .../Events/AppInfoSecretChangedEvent.cs | 10 -- ...eEvent.cs => ConfigurationDisableEvent.cs} | 2 +- ...dEvent.cs => ConfigurationEnabledEvent.cs} | 2 +- ...dEvent.cs => ConfigurationUpdatedEvent.cs} | 2 +- .../ConfigurationNotFoundException.cs | 7 +- .../Properties/Resources.resx | 146 ++++++------------ .../Properties/Resources.zh-Hans.resx | 52 +++---- .../Properties/Resources.zh-Hant.resx | 62 ++++---- .../Configs/ConfigurationAuthorizeUseCase.cs | 2 +- ...se.cs => ConfigurationPushRedisUseCase.cs} | 16 +- 14 files changed, 179 insertions(+), 271 deletions(-) delete mode 100644 Source/Starfish.Service/Domain/Events/AppInfoSecretChangedEvent.cs rename Source/Starfish.Service/Domain/Events/{AppInfoDisableEvent.cs => ConfigurationDisableEvent.cs} (71%) rename Source/Starfish.Service/Domain/Events/{AppInfoEnabledEvent.cs => ConfigurationEnabledEvent.cs} (71%) rename Source/Starfish.Service/Domain/Events/{AppInfoUpdatedEvent.cs => ConfigurationUpdatedEvent.cs} (71%) rename Source/Starfish.Service/UseCases/Configs/{PushRedisUseCase.cs => ConfigurationPushRedisUseCase.cs} (67%) diff --git a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs index 61d2c03..1a8a2fe 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -155,8 +155,8 @@ public Task GetItemsInTextAsync(string id, string format, CancellationTo public Task PushRedisAsync(string id, ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default) { - var useCase = LazyServiceProvider.GetRequiredService(); - var input = new PushRedisInput(id, data); + 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/Subscribers/LoggingEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs index 8d7982b..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); - } - /// /// 处理配置节点创建事件 /// @@ -195,7 +172,7 @@ public Task HandleAsync(ConfigurationCreatedEvent @event, MessageContext context var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "create", Description = description, OperateTime = DateTime.Now, @@ -220,7 +197,7 @@ public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "delete", Description = description, OperateTime = DateTime.Now, @@ -230,6 +207,13 @@ 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) { @@ -238,7 +222,7 @@ public Task HandleAsync(ConfigurationPublishedEvent @event, MessageContext conte var command = new OperateLogCreateCommand { - Module = "config", + Module = MODULE_CONFIG, Type = "publish", Description = description, OperateTime = DateTime.Now, diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 3a5ab79..7bfcb9a 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -24,10 +24,6 @@ private Configuration() { Secret = @event.Secret; }); - Register(_ => - { - SetStatus(ConfigurationStatus.Published); - }); Register(_ => { SetStatus(ConfigurationStatus.Pending); @@ -126,16 +122,6 @@ internal void SetName(string name) RaiseEvent(new ConfigurationNameChangedEvent(Name, name)); } - private void SetStatus(ConfigurationStatus status) - { - if (Status == status) - { - return; - } - - RaiseEvent(new ConfigurationStatusChangedEvent(Status, status)); - } - /// /// 设置访问密钥 /// @@ -234,24 +220,17 @@ internal void Publish(string version, string comment, string @operator) if (Items == null || Items.Count == 0) { - throw new InvalidOperationException("配置项为空"); + 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()); } - private void EnsureStatus() - { - if (Status == ConfigurationStatus.Disabled) - { - throw new ConfigurationDisabledException(Id); - } - } - internal void Disable() { if (Status == ConfigurationStatus.Disabled) @@ -260,6 +239,7 @@ internal void Disable() } SetStatus(ConfigurationStatus.Disabled); + RaiseEvent(new ConfigurationDisableEvent()); } internal void Enable() @@ -270,10 +250,29 @@ internal void Enable() } SetStatus(ConfigurationStatus.Pending); + RaiseEvent(new ConfigurationEnabledEvent()); } internal void SetDescription(string description) { Description = description; } + + private void EnsureStatus() + { + if (Status == ConfigurationStatus.Disabled) + { + throw new ConfigurationDisabledException(Id); + } + } + + 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/Business/ConfigurationGeneralBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs index b5b7750..a17bf6e 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationGeneralBusiness.cs @@ -137,6 +137,8 @@ protected override async Task UpdateAsync(CancellationToken cancellationToken = Aggregate.SetDescription(Description); } + Aggregate.RaiseEvent(new ConfigurationUpdatedEvent()); + await ConfigurationRepository.UpdateAsync(Aggregate, true, cancellationToken); } 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/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/ConfigurationNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs index c317fca..de42b28 100644 --- a/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs +++ b/Source/Starfish.Service/Domain/Exceptions/ConfigurationNotFoundException.cs @@ -5,8 +5,13 @@ /// public class ConfigurationNotFoundException : NotFoundException { + public ConfigurationNotFoundException() + : base(Resources.IDS_ERROR_CONFIG_NOT_EXISTS) + { + } + public ConfigurationNotFoundException(string id) - : base(string.Format(Resources.IDS_ERROR_CONFIG_NOT_EXISTS, 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/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index 9373b52..eeee88e 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -1,17 +1,17 @@  - @@ -119,230 +119,170 @@ Development - Performance Evaluation Testing - Production - Simulation Testing - System Integration Testing - User Acceptance Testing - System administrator - Disabled - Pending - Published - Authorize failed. - You are not authorized to operate. - Data format '{0}' is not supported. - Data format required. - Configuration was disabled, [Id]:{0}. - Configuration was duplicated. - Configuration key '{0}' exists. - Configuration key '{0}' 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. - The query parameter 'count' must be greater than 0. - The query parameter 'skip' can not be a negative number. - The password is not correct. - Refresh token is expired. - Refresh token is invalid. - Refresh_token is required. - Team not exists, [Id]:{0}. - The team owner can not be removed. - User id(s) require. - Unsupported cache provider '{0}'. - Unsupported database provider '{0}'. - Unsupported service bus provider '{0}'. - Email '{0}' not available. - The user was locked out. - Not allowed to change role for reserved user. - Not allowed to delete reserved user. - User not exists, [Id]:{0}. - The password must be 8-32 characters long, contain at least one uppercase letter, one lowercase letter. - Password is required. - Username or password is invalid. - 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. - User authenticate successfully. - Create configuration, [Id]:{0}, [Name]:{1}. - Delete configuration, [Id]:{0}, [Name]:{1}. - + + + Disable configuration, [Id]:{0}, [Name]:{1}. + + + Enable configuration, [Id]:{0}, [Name]:{1}. Publish configuration, [Id]:{0}, [Name]:{1}. - + + + Reset configuration secret, [Id]:{0}, [Name]:{1}. Update configuration, [Id]:{0}, [Name]:{1}. - + + + Configuration not exists. \ 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 c6bab5f..7d5aeeb 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx @@ -189,7 +189,7 @@ 配置项 '{0}' 不存在。 - + 配置不存在,[Id]:{0}。 @@ -297,30 +297,6 @@ 用户名'{0}'不可用。 - - 新增应用 {0}({1})。 - - - - 删除应用 {0}({1})。 - - - - 禁用应用 {0}({1})。 - - - - 启用应用 {0}({1})。 - - - - 重置应用密钥 {0}({1})。 - - - - 更新应用 {0}({1})。 - - 用户认证失败。 @@ -330,19 +306,37 @@ - 新增配置,[应用]:{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 9291610..61e759c 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx @@ -174,23 +174,23 @@ - 設置已停用,[Id]:{0}。 + 配置已停用,[Id]:{0}。 - 設置重複。 + 配置重複。 - 設置項目“{0}”已經存在。 + 配置項“{0}”已經存在。 - 設置項目“{0}”不存在。 + 配置項“{0}”不存在。 - - 設定不存在,[Id]:{0}。 + + 配置不存在,[Id]:{0}。 @@ -297,30 +297,6 @@ 用戶名“{0}”不可用。 - - 新增應用程式 {0}({1})。 - - - - 刪除應用程式 {0}({1})。 - - - - 停用應用程式 {0}({1})。 - - - - 啟用應用程式 {0}({1})。 - - - - 重設應用程式密鑰 {0}({1})。 - - - - 更新應用程式 {0}({1})。 - - 用戶身份驗證失敗。 @@ -330,19 +306,37 @@ - 建立設置,[應用程式]:{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/UseCases/Configs/ConfigurationAuthorizeUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs index c2f4a17..6f3e615 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationAuthorizeUseCase.cs @@ -44,7 +44,7 @@ public async Task ExecuteAsync(ConfigurationAuthor if (configuration == null) { - throw new ConfigurationNotFoundException(string.Empty); + throw new ConfigurationNotFoundException(); } var encryptedSecret = Cryptography.SHA.Encrypt(input.Secret); diff --git a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs similarity index 67% rename from Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs rename to Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs index 4941ec5..91d0532 100644 --- a/Source/Starfish.Service/UseCases/Configs/PushRedisUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPushRedisUseCase.cs @@ -7,26 +7,26 @@ namespace Nerosoft.Starfish.UseCases; -internal interface IPushRedisUseCase : INonOutputUseCase; +internal interface IConfigurationPushRedisUseCase : INonOutputUseCase; -internal record PushRedisInput(string Id, ConfigurationPushRedisRequestDto Data) : IUseCaseInput; +internal record ConfigurationPushRedisInput(string Id, ConfigurationPushRedisRequestDto Data) : IUseCaseInput; -internal sealed class PushRedisUseCase : IPushRedisUseCase +internal sealed class ConfigurationPushRedisUseCase : IConfigurationPushRedisUseCase { private readonly IConfigurationRepository _configurationRepository; - private readonly ITeamRepository _appInfoRepository; + private readonly ITeamRepository _teamRepository; private readonly UserPrincipal _identity; - public PushRedisUseCase(IConfigurationRepository configurationRepository, ITeamRepository appInfoRepository, UserPrincipal identity) + public ConfigurationPushRedisUseCase(IConfigurationRepository configurationRepository, ITeamRepository teamRepository, UserPrincipal identity) { _configurationRepository = configurationRepository; - _appInfoRepository = appInfoRepository; + _teamRepository = teamRepository; _identity = identity; } - public async Task ExecuteAsync(PushRedisInput input, CancellationToken cancellationToken = default) + public async Task ExecuteAsync(ConfigurationPushRedisInput input, CancellationToken cancellationToken = default) { - var permission = await _appInfoRepository.CheckPermissionAsync(input.Id, _identity.UserId, cancellationToken); + var permission = await _teamRepository.CheckPermissionAsync(input.Id, _identity.UserId, cancellationToken); if (permission != PermissionState.Edit) { From f0cffd9ee97db06373adac0f7f5f5f97a5b22c54 Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 18 Feb 2024 23:22:31 +0800 Subject: [PATCH 12/26] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ConfigurationController.cs | 6 ++-- .../Rest/Defines/IAdministratorApi.cs | 19 ++++++++++++ .../Starfish.Webapp/Rest/Defines/IAppsApi.cs | 31 ------------------- .../Rest/Defines/IConfigurationApi.cs | 13 ++++++-- .../Rest/ServiceCollectionExtensions.cs | 2 +- 5 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 Source/Starfish.Webapp/Rest/Defines/IAdministratorApi.cs delete mode 100644 Source/Starfish.Webapp/Rest/Defines/IAppsApi.cs diff --git a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index a8df173..413e726 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -111,7 +111,7 @@ public async Task DeleteAsync(string id) /// /// /// - [HttpPatch("{id}/secret")] + [HttpPut("{id}/secret")] public async Task SetSecretAsync(string id, [FromBody] ConfigurationSecretSetRequestDto data) { await _service.SetSecretAsync(id, data.Secret, HttpContext.RequestAborted); @@ -123,7 +123,7 @@ public async Task SetSecretAsync(string id, [FromBody] Configurat /// /// /// - [HttpPatch("{id}/disable")] + [HttpPut("{id}/disable")] public async Task DisableAsync(string id) { await _service.DisableAsync(id, HttpContext.RequestAborted); @@ -135,7 +135,7 @@ public async Task DisableAsync(string id) /// /// /// - [HttpPatch("{id}/enable")] + [HttpPut("{id}/enable")] public async Task EnableAsync(string id) { await _service.EnableAsync(id, HttpContext.RequestAborted); 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 2244017..75ab306 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -23,11 +23,20 @@ internal interface IConfigurationApi [Delete("/api/configuration/{id}")] Task DeleteAsync(string id, CancellationToken cancellationToken = default); + [Put("/api/configuration/{id}/secret")] + Task SetSecretAsync(string id, [Body] ConfigurationSecretSetRequestDto data, CancellationToken cancellationToken = default); + + [Put("/api/Configuration/{id}/disable")] + Task DisableAsync(string id, CancellationToken cancellationToken = default); + + [Put("/api/Configuration/{id}/enable")] + Task EnableAsync(string id, CancellationToken cancellationToken = default); + [Post("/api/configuration/{id}/publish")] - Task PublishAsync(string id, [Body] ConfigurationPublishDto data, CancellationToken cancellationToken = default); + Task PublishAsync(string id, [Body] ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default); [Post("/api/configuration/{id}/redis")] - Task PushRedisAsync(string id, [Body] PushRedisRequestDto data, CancellationToken cancellationToken = default); + Task PushRedisAsync(string id, [Body] ConfigurationPushRedisRequestDto data, CancellationToken cancellationToken = default); [Get("/api/configuration/{id}/item")] [Headers("x-format: application/json")] 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) => From 6edaa2368709a5e87bbfb6f25298c8b0f1129dad Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:29:16 +0800 Subject: [PATCH 13/26] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Packages.props | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) 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 From 6aa7550f8ee7fd76f75fa3aca6930617e52017db Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:38:45 +0800 Subject: [PATCH 14/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E9=A1=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfigurationItemsUpdateCommand.cs | 8 ++++- .../IConfigurationApplicationService.cs | 2 +- .../ConfigurationApplicationService.cs | 4 +-- .../Starfish.Service/Starfish.Service.csproj | 1 + .../ConfigurationItemsUpdateUseCase.cs | 9 +++--- .../Configs/ConfigurationItemsUpdateDto.cs | 29 +++++++++++++++++++ .../Controllers/ConfigurationController.cs | 6 ++-- 7 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 Source/Starfish.Transit/Configs/ConfigurationItemsUpdateDto.cs diff --git a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs index 9f6c187..cd7c293 100644 --- a/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs +++ b/Source/Starfish.Service/Application/Commands/Configs/ConfigurationItemsUpdateCommand.cs @@ -4,14 +4,20 @@ namespace Nerosoft.Starfish.Application; public sealed class ConfigurationItemsUpdateCommand : Command { - public ConfigurationItemsUpdateCommand(string id, IDictionary items) + public ConfigurationItemsUpdateCommand(string id, string mode, IDictionary items) { Id = id; + Mode = mode; Items = items; } public string Id { get; set; } + /// + /// 更新方式 + /// + public string Mode { get; set; } + /// /// 所有配置项 /// diff --git a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs index e756e0d..44fa235 100644 --- a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs @@ -118,7 +118,7 @@ public interface IConfigurationApplicationService : IApplicationService /// /// /// - Task UpdateItemsAsync(string id, string format, string data, CancellationToken cancellationToken = default); + Task UpdateItemsAsync(string id, ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default); /// /// 发布配置 diff --git a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs index 1a8a2fe..efdf4ff 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -114,10 +114,10 @@ public Task UpdateValueAsync(string id, string key, string value, CancellationTo return useCase.ExecuteAsync(input, cancellationToken); } - public Task UpdateItemsAsync(string id, string format, string data, CancellationToken cancellationToken = default) + public Task UpdateItemsAsync(string id, ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationItemsUpdateInput(id, format, data); + var input = new ConfigurationItemsUpdateInput(id, data); return useCase.ExecuteAsync(input, cancellationToken); } 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/Configs/ConfigurationItemsUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs index bdfda1b..50a9809 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs @@ -1,12 +1,13 @@ using Nerosoft.Euonia.Application; using Nerosoft.Euonia.Bus; using Nerosoft.Starfish.Application; +using Nerosoft.Starfish.Transit; namespace Nerosoft.Starfish.UseCases; public interface IConfigurationItemsUpdateUseCase : INonOutputUseCase; -public record ConfigurationItemsUpdateInput(string Id, string Format, string Data); +public record ConfigurationItemsUpdateInput(string Id, ConfigurationItemsUpdateDto Data); public class ConfigurationItemsUpdateUseCase : IConfigurationItemsUpdateUseCase { @@ -21,7 +22,7 @@ public ConfigurationItemsUpdateUseCase(IBus bus, IServiceProvider provider) public Task ExecuteAsync(ConfigurationItemsUpdateInput input, CancellationToken cancellationToken = default) { - var format = input.Format?.Normalize(TextCaseType.Lower).Trim(TextTrimType.All); + var format = input.Data.Type?.Normalize(TextCaseType.Lower).Trim(TextTrimType.All); var parserName = format switch { Constants.Configuration.FormatText => "text", @@ -32,8 +33,8 @@ public Task ExecuteAsync(ConfigurationItemsUpdateInput input, CancellationToken }; var parser = _provider.GetKeyedService(parserName); - var data = Cryptography.Base64.Decrypt(input.Data); - var command = new ConfigurationItemsUpdateCommand(input.Id, parser.Parse(data)); + 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 => 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.Webapi/Controllers/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index 413e726..002d481 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -227,14 +227,12 @@ public async Task UpdateValueAsync(string id, string key, [FromBo /// 更新配置项 /// /// - /// /// /// [HttpPut("{id}/item")] - [Consumes("text/plain")] - public async Task UpdateItemsAsync(string id, [FromHeader(Name = "x-format")] string format, [FromBody] string data) + public async Task UpdateItemsAsync(string id, [FromBody] ConfigurationItemsUpdateDto data) { - await _service.UpdateItemsAsync(id, format, data, HttpContext.RequestAborted); + await _service.UpdateItemsAsync(id, data, HttpContext.RequestAborted); return Ok(); } } \ No newline at end of file From c3e5a66c8d0450fb5b423bc0b6573f9ba21b3734 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:39:14 +0800 Subject: [PATCH 15/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E9=A1=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs index 75ab306..d2486d6 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -52,5 +52,5 @@ internal interface IConfigurationApi Task UpdateValueAsync(string id, string key, [Body] string data, CancellationToken cancellationToken = default); [Put("/api/configuration/{id}/item")] - Task UpdateItemsAsync(string id, [Header("x-format")] string format, [Body] string data, CancellationToken cancellationToken = default); + Task UpdateItemsAsync(string id, [Body] ConfigurationItemsUpdateDto data, CancellationToken cancellationToken = default); } \ No newline at end of file From d87b5bfb66ab8848f7d099cd31f5e3ca5e59e7a4 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:41:20 +0800 Subject: [PATCH 16/26] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Configs/EditDialogArgs.cs | 9 +- .../Pages/Configs/EditItems.razor | 111 ++++++++++++++++++ .../Pages/Configs/EditValue.razor | 8 +- 3 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 Source/Starfish.Webapp/Pages/Configs/EditItems.razor 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); } From 7d001a28bf959240b7087651c9ae802c1b456b32 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:42:12 +0800 Subject: [PATCH 17/26] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=AF=86=E9=92=A5=E9=A1=B5=E9=9D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/{Apps => Configs}/ResetSecret.razor | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename Source/Starfish.Webapp/Pages/{Apps => Configs}/ResetSecret.razor (90%) diff --git a/Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor similarity index 90% rename from Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor rename to Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor index ca2c9d2..1b838f7 100644 --- a/Source/Starfish.Webapp/Pages/Apps/ResetSecret.razor +++ b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor @@ -1,6 +1,6 @@ @implements IDialogContentComponent -@inject IAppsApi AppsApi +@inject IConfigurationApi Api @@ -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); } From 16499a6a4023d5b9c38bef14fe5bc9c3df650b8d Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:43:32 +0800 Subject: [PATCH 18/26] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=B0redis=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Pages/Configs/SyncRedis.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 1233153811707dcac49bb9631300650535c4e907 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 21:44:06 +0800 Subject: [PATCH 19/26] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=91=E5=B8=83dialo?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Pages/Configs/Publish.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 5fe4931126eea9615ee48b60767ea174a2c52209 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 19 Feb 2024 23:25:25 +0800 Subject: [PATCH 20/26] =?UTF-8?q?=E5=88=A0=E9=99=A4app=E7=9B=B8=E5=85=B3dt?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Starfish.Transit/Apps/AppInfoCreateDto.cs | 32 ------------- .../Starfish.Transit/Apps/AppInfoCriteria.cs | 30 ------------ .../Starfish.Transit/Apps/AppInfoDetailDto.cs | 47 ------------------ .../Starfish.Transit/Apps/AppInfoItemDto.cs | 48 ------------------- .../Starfish.Transit/Apps/AppInfoUpdateDto.cs | 22 --------- 5 files changed, 179 deletions(-) delete mode 100644 Source/Starfish.Transit/Apps/AppInfoCreateDto.cs delete mode 100644 Source/Starfish.Transit/Apps/AppInfoCriteria.cs delete mode 100644 Source/Starfish.Transit/Apps/AppInfoDetailDto.cs delete mode 100644 Source/Starfish.Transit/Apps/AppInfoItemDto.cs delete mode 100644 Source/Starfish.Transit/Apps/AppInfoUpdateDto.cs 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 From 8d81f8ffa4b6aa76e31c15058cf371e642f3a75d Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 20 Feb 2024 22:31:28 +0800 Subject: [PATCH 21/26] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Properties/Resources.resx | 6 +- .../Properties/Resources.zh-Hans.resx | 12 +- .../Properties/Resources.zh-Hant.resx | 12 +- .../Starfish.Webapp/Properties/Resources.resx | 137 +++++++++--------- .../Properties/Resources.zh-Hans.resx | 137 +++++++++--------- .../Properties/Resources.zh-Hant.resx | 137 +++++++++--------- 6 files changed, 216 insertions(+), 225 deletions(-) diff --git a/Source/Starfish.Service/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index eeee88e..10f0254 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -171,6 +171,9 @@ Configuration key '{0}' not exists. + + Configuration not exists. + Configuration not exists, [Id]:{0}. @@ -282,7 +285,4 @@ Update configuration, [Id]:{0}, [Name]:{1}. - - Configuration not exists. - \ 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 7d5aeeb..42dc9ad 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx @@ -189,10 +189,16 @@ 配置项 '{0}' 不存在。 + + 配置不存在。 + 配置不存在,[Id]:{0}。 + + 没有找到配置项。 + 没有待发布的配置。 @@ -333,10 +339,4 @@ 更新配置,[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 61e759c..c810ce7 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx @@ -189,10 +189,16 @@ 配置項“{0}”不存在。 + + 配置不存在。 + 配置不存在,[Id]:{0}。 + + 沒有找到配置項。 + 沒有待發布的設定。 @@ -333,10 +339,4 @@ 更新配置,[Id]:{0},[名稱]:{1}。 - - 沒有找到配置項。 - - - 配置不存在。 - \ No newline at end of file diff --git a/Source/Starfish.Webapp/Properties/Resources.resx b/Source/Starfish.Webapp/Properties/Resources.resx index a9e137d..fb67c25 100644 --- a/Source/Starfish.Webapp/Properties/Resources.resx +++ b/Source/Starfish.Webapp/Properties/Resources.resx @@ -117,75 +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 @@ -259,17 +190,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 +252,9 @@ Environment + + Add configuration + Delete @@ -300,6 +273,15 @@ Key + + Name + + + Status + + + Team + Value @@ -339,6 +321,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 @@ -420,6 +411,9 @@ Apps + + Configurations + Home @@ -585,4 +579,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..14c61c8 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx @@ -117,75 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 应用详情 - - - 应用代码 - - - 应用描述 - - - 应用名称 - - - 应用状态 - - - 团队 - - - 应用代码 - - - 应用描述 - - - 应用名称 - - - 访问密钥 - - - 选择所属团队 - - - 新增应用 - - - 编辑应用 - - - 新增 - - - 代码 - - - 应用Id - - - 名称 - - - 状态 - - - 团队 - - - 确定要删除应用 '{0}'? - - - 删除应用 - - - 访问密钥将被加密存储且无法解密,请自行保管。如果忘记密钥,请重新设置。 - - - 重置密钥 - 应用详情 @@ -259,17 +190,41 @@ - 确定要删除配置吗? + 确定要删除配置'{0}'吗? 删除配置 + + Id + + + 配置详情 + + + 描述 + + + 名称 + + + 密钥 + + + 选择团队 + + + 新增配置 + 从Json创建 从文本创建 + + 编辑配置 + 编辑Json @@ -282,6 +237,9 @@ 应用环境 + + 新增配置 + 删除 @@ -300,6 +258,15 @@ + + 名称 + + + 状态 + + + 团队 + @@ -339,6 +306,15 @@ 发布配置 + + 密钥 + + + 访问密钥将被加密存储且无法解密,请自行保管。如果忘记密钥,请重新设置。 + + + 重置密钥 + 开始同步 @@ -420,6 +396,9 @@ 应用 + + 配置 + 首页 @@ -585,4 +564,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..bd18c8f 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx @@ -117,75 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 應用詳情 - - - 應用代碼 - - - 應用描述 - - - 應用名稱 - - - 應用狀態 - - - 團隊 - - - 應用代碼 - - - 應用描述 - - - 應用名稱 - - - 訪問密鑰 - - - 選擇所屬團隊 - - - 新增應用 - - - 編輯應用 - - - 新增 - - - 代碼 - - - 應用Id - - - 姓名 - - - 狀態 - - - 團隊 - - - 確定要刪除此應用“{0}”嗎? - - - 刪除應用 - - - 存取密鑰將被加密儲存且無法解密,請自行保管。 如果忘記密鑰,請重新設定。 - - - 重置密鑰 - 應用詳情 @@ -259,11 +190,14 @@ - 確定要刪除配置嗎? + 確定要刪除配置'{0}'嗎? 刪除配置 + + Id + 從Json創建 @@ -282,6 +216,9 @@ 應用環境 + + 新增配置 + 刪除 @@ -339,6 +276,15 @@ 發佈配置 + + 密鑰 + + + 存取密鑰將被加密儲存且無法解密,請自行保管。 如果忘記密鑰,請重新設定。 + + + 重置密鑰 + 開始同步 @@ -420,6 +366,9 @@ 應用 + + 配置 + 首頁 @@ -585,4 +534,52 @@ 用戶名 + + 重設密碼 + + + 描述 + + + 名稱 + + + 發佈時間 + + + 狀態 + + + 版本 + + + 配置詳情 + + + 描述 + + + 名稱 + + + 密鑰 + + + 選擇團隊 + + + 新增配置 + + + 編輯配置 + + + 名稱 + + + 狀態 + + + 團隊 + \ No newline at end of file From ece998b8cdd9faa2de0d0fdf774cd4e34e97043e Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 20 Feb 2024 22:32:09 +0800 Subject: [PATCH 22/26] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Starfish.Webapp/Pages/Apps/Detail.razor | 83 -------- Source/Starfish.Webapp/Pages/Apps/Edit.razor | 185 ------------------ Source/Starfish.Webapp/Pages/Apps/Index.razor | 166 ---------------- 3 files changed, 434 deletions(-) delete mode 100644 Source/Starfish.Webapp/Pages/Apps/Detail.razor delete mode 100644 Source/Starfish.Webapp/Pages/Apps/Edit.razor delete mode 100644 Source/Starfish.Webapp/Pages/Apps/Index.razor diff --git a/Source/Starfish.Webapp/Pages/Apps/Detail.razor b/Source/Starfish.Webapp/Pages/Apps/Detail.razor deleted file mode 100644 index baed1c6..0000000 --- a/Source/Starfish.Webapp/Pages/Apps/Detail.razor +++ /dev/null @@ -1,83 +0,0 @@ -@implements IDialogContentComponent - -@inject IAppsApi AppsApi - - - - - - @Dialog.Instance.Parameters.Title - - - - - - @if (Loading) - { - - - - } - else - { - - - - - - - - - - - } - - - - - @(Resources.IDS_COMMON_CLOSE) - - -@code { - [Parameter] - public string Content { get; set; } - - [CascadingParameter] - public FluentDialog Dialog { get; set; } = default!; - - private bool Loading { get; set; } - - private AppInfoDetailDto Data { get; } = new(); - - protected override async Task OnInitializedAsync() - { - try - { - Loading = true; - - await AppsApi.GetAsync(Content).EnsureSuccess(result => - { - Data.Name = result.Name; - Data.Description = result.Description; - Data.Status = result.Status; - }); - } - catch (Exception exception) - { - exception.Send(); - } - finally - { - Loading = false; - } - } - - private async Task CancelAsync() - { - await Dialog.CancelAsync(); - } -} \ No newline at end of file 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 From ac16d2f0318f8652e16751e5d6f30d6a61f08f06 Mon Sep 17 00:00:00 2001 From: damon Date: Wed, 21 Feb 2024 00:35:45 +0800 Subject: [PATCH 23/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mappings/ConfigurationMappingProfile.cs | 2 ++ .../Domain/Aggregates/ConfigurationRevision.cs | 2 +- .../Domain/Business/ConfigurationItemsBusiness.cs | 2 +- .../Repository/Contexts/DataContext.cs | 4 +++- .../Contexts/RelationalDatabaseModelBuilder.cs | 11 ++++++----- Source/Starfish.Service/UseCases/UseCaseModule.cs | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs b/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs index 45d4f8c..9ccc295 100644 --- a/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs +++ b/Source/Starfish.Service/Application/Mappings/ConfigurationMappingProfile.cs @@ -15,6 +15,8 @@ public ConfigurationMappingProfile() CreateMap(); 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/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/ConfigurationItemsBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs index c270afa..f8438fe 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationItemsBusiness.cs @@ -22,7 +22,7 @@ protected async Task ExecuteAsync(string id, IDictionary items, throw new ConfigurationNotFoundException(id); } - var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + var permission = await TeamRepository.CheckPermissionAsync(aggregate.TeamId, Identity.UserId, cancellationToken); switch (permission) { 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 ac76a07..60f1a0f 100644 --- a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs +++ b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs @@ -114,7 +114,7 @@ protected override ModelBuilder ConfigureConfiguration(ModelBuilder modelBuilder entity.Property(t => t.Id) .IsRequired() - .HasValueGenerator(); + .HasValueGenerator(); entity.HasMany(t => t.Items) .WithOne() @@ -125,6 +125,11 @@ protected override ModelBuilder ConfigureConfiguration(ModelBuilder modelBuilder .WithOne() .HasForeignKey(t => t.ConfigurationId) .OnDelete(DeleteBehavior.Cascade); + + entity.HasOne(t => t.Archive) + .WithOne() + .HasForeignKey() + .OnDelete(DeleteBehavior.Cascade); }); } @@ -161,10 +166,6 @@ protected override ModelBuilder ConfigureConfigurationArchive(ModelBuilder model entity.Property(t => t.Id) .IsRequired(); - - entity.HasOne(t => t.Configuration) - .WithOne(t => t.Archive) - .HasForeignKey(nameof(ConfigurationArchive.Id)); }); } 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) { From 0f93bd8712661ef91b782d470ae126bbb630193f Mon Sep 17 00:00:00 2001 From: damon Date: Wed, 21 Feb 2024 00:41:43 +0800 Subject: [PATCH 24/26] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Starfish.Webapp/Layout/MainLayout.razor | 2 +- .../Pages/Configs/Detail.razor | 87 ++++++ .../Starfish.Webapp/Pages/Configs/Edit.razor | 172 +++++++---- .../Starfish.Webapp/Pages/Configs/Index.razor | 277 ++++++------------ .../Starfish.Webapp/Pages/Configs/Items.razor | 174 +++++++++++ .../Pages/Configs/ResetSecret.razor | 6 +- .../Pages/Configs/Revision.razor | 11 +- .../Starfish.Webapp/Pages/Team/Detail.razor | 58 +--- .../Pages/User/ResetPassword.razor | 2 +- .../Starfish.Webapp/Properties/Resources.resx | 6 - .../Properties/Resources.zh-Hans.resx | 6 - .../Properties/Resources.zh-Hant.resx | 6 - .../Rest/Defines/IConfigurationApi.cs | 9 +- 13 files changed, 495 insertions(+), 321 deletions(-) create mode 100644 Source/Starfish.Webapp/Pages/Configs/Detail.razor create mode 100644 Source/Starfish.Webapp/Pages/Configs/Items.razor 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/Configs/Detail.razor b/Source/Starfish.Webapp/Pages/Configs/Detail.razor new file mode 100644 index 0000000..53019b6 --- /dev/null +++ b/Source/Starfish.Webapp/Pages/Configs/Detail.razor @@ -0,0 +1,87 @@ +@implements IDialogContentComponent + +@inject IConfigurationApi ConfigurationApi + + + + + + @Dialog.Instance.Parameters.Title + + + + + + @if (Loading) + { + + + + } + else + { + + + + + + + + + + + } + + + + + @(Resources.IDS_COMMON_CLOSE) + + +@code { + + [Parameter] + public string Content { get; set; } + + [CascadingParameter] + public FluentDialog Dialog { get; set; } = default!; + + private bool Loading { get; set; } + + private ConfigurationDto Data { get; } = new(); + + protected override async Task OnInitializedAsync() + { + try + { + Loading = true; + + await ConfigurationApi.GetAsync(Content).EnsureSuccess(result => + { + Data.Name = result.Name; + Data.Description = result.Description; + Data.StatusName = result.StatusName; + Data.Version = result.Version; + Data.PublishTime = result.PublishTime; + }); + } + catch (Exception exception) + { + exception.Send(); + } + finally + { + Loading = false; + } + } + + private async Task CancelAsync() + { + 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/Index.razor b/Source/Starfish.Webapp/Pages/Configs/Index.razor index da09144..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 (Configuration != null) - { - - - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_VERSION, Configuration?.Version ?? "--") - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_PUBLISH_TIME, Configuration?.PublishTime) - @string.Format(Resources.IDS_CONFIG_INDEX_PANEL_LABEL_CONFIG_UPDATE_TIME, Configuration?.UpdateTime) - - - } - - - - @(Resources.IDS_CONFIG_INDEX_BUTTON_SYNC_REDIS) - @(Resources.IDS_CONFIG_INDEX_BUTTON_DELETE) - - @if (Configuration?.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 ConfigurationDto Configuration { 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 => Configuration = 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"] = Configuration == null ? "create" : "update", - ["format"] = Constants.Configuration.FormatJson - } - }; - var title = Configuration == 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"] = Configuration == null ? "create" : "update", - ["format"] = Constants.Configuration.FormatText - } - }; - - var title = Configuration == 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/ResetSecret.razor b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor index 1b838f7..7715eb3 100644 --- a/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor +++ b/Source/Starfish.Webapp/Pages/Configs/ResetSecret.razor @@ -6,7 +6,7 @@ - @(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) 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/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 fb67c25..b20cb57 100644 --- a/Source/Starfish.Webapp/Properties/Resources.resx +++ b/Source/Starfish.Webapp/Properties/Resources.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Detail - Configuration @@ -408,9 +405,6 @@ User name - - Apps - Configurations diff --git a/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx b/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx index 14c61c8..9bc2745 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 应用详情 - 应用配置 @@ -393,9 +390,6 @@ 用户名 - - 应用 - 配置 diff --git a/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx b/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx index bd18c8f..7c06b55 100644 --- a/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 應用詳情 - 應用配置 @@ -363,9 +360,6 @@ 用戶名 - - 應用 - 配置 diff --git a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs index d2486d6..b879cfa 100644 --- a/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs +++ b/Source/Starfish.Webapp/Rest/Defines/IConfigurationApi.cs @@ -26,11 +26,8 @@ internal interface IConfigurationApi [Put("/api/configuration/{id}/secret")] Task SetSecretAsync(string id, [Body] ConfigurationSecretSetRequestDto data, CancellationToken cancellationToken = default); - [Put("/api/Configuration/{id}/disable")] - Task DisableAsync(string id, CancellationToken cancellationToken = default); - - [Put("/api/Configuration/{id}/enable")] - Task EnableAsync(string id, CancellationToken cancellationToken = default); + [Put("/api/Configuration/{id}/{availability}")] + Task ChangeStatusAsync(string id, string availability, CancellationToken cancellationToken = default); [Post("/api/configuration/{id}/publish")] Task PublishAsync(string id, [Body] ConfigurationPublishRequestDto data, CancellationToken cancellationToken = default); @@ -40,7 +37,7 @@ internal interface IConfigurationApi [Get("/api/configuration/{id}/item")] [Headers("x-format: application/json")] - Task>> GetItemListAsync(string id, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); + Task>> GetItemListAsync(string id, string keyword, int skip = Constants.Query.Skip, int count = Constants.Query.Count, CancellationToken cancellationToken = default); [Get("/api/configuration/{id}/item")] Task> GetItemsAsync(string id, [Header("x-format")] string format, CancellationToken cancellationToken = default); From ec8d7cdf0d49cbddcae449c5a892b49f40caabb2 Mon Sep 17 00:00:00 2001 From: damon Date: Wed, 21 Feb 2024 18:42:27 +0800 Subject: [PATCH 25/26] =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=B1=BB=E8=AE=BF=E9=97=AE=E4=BF=AE=E9=A5=B0=E7=AC=A6=E6=94=B9?= =?UTF-8?q?=E4=B8=BAinternal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IConfigurationApplicationService.cs | 7 ++-- .../ConfigurationApplicationService.cs | 12 +++---- .../Implements/IdentityApplicationService.cs | 11 ++---- .../Implements/LogsApplicationService.cs | 2 +- .../Implements/TeamApplicationService.cs | 2 +- .../Implements/UserApplicationService.cs | 2 +- .../Repositories/IConfigurationRepository.cs | 4 +-- .../Repositories/ConfigurationRepository.cs | 35 ++++++++++++++++--- .../Configs/ConfigurationCreateUseCase.cs | 6 ++-- .../Configs/ConfigurationDeleteUseCase.cs | 6 ++-- .../ConfigurationItemsUpdateUseCase.cs | 6 ++-- .../Configs/ConfigurationPublishUseCase.cs | 6 ++-- .../Configs/ConfigurationQueryUseCase.cs | 6 ++-- .../Configs/ConfigurationUpdateUseCase.cs | 6 ++-- .../ConfigurationValueUpdateUseCase.cs | 6 ++-- .../Configs/GetConfigurationArchiveUseCase.cs | 8 ++--- .../Configs/GetConfigurationDetailUseCase.cs | 8 ++--- .../GetConfigurationItemCountUseCase.cs | 11 +++--- .../GetConfigurationItemListUseCase.cs | 12 +++---- .../Configs/SetConfigurationSecretUseCase.cs | 6 ++-- .../Identity/ChangePasswordUseCase.cs | 6 ++-- .../Identity/GrantWithPasswordUseCase.cs | 21 +++-------- .../Identity/GrantWithRefreshTokenUseCase.cs | 16 +++------ .../Identity/IdentityCommonComponent.cs | 2 +- .../Identity/IdentityUseCaseOutput.cs | 2 +- .../UseCases/Identity/ResetPasswordUseCase.cs | 6 ++-- .../UseCases/Identity/UserCountUseCase.cs | 4 +-- .../UseCases/Identity/UserCreateUseCase.cs | 8 ++--- .../UseCases/Identity/UserDeleteUseCase.cs | 6 ++-- .../UseCases/Identity/UserDetailUseCase.cs | 8 ++--- .../UseCases/Identity/UserQueryUseCase.cs | 20 +++-------- .../UseCases/Identity/UserUpdateUseCase.cs | 6 ++-- .../UseCases/Logging/LogsCountUseCase.cs | 8 ++--- .../UseCases/Logging/LogsQueryUseCase.cs | 28 +++------------ .../UseCases/Team/TeamCountUseCase.cs | 8 ++--- .../UseCases/Team/TeamCreateUseCase.cs | 8 ++--- .../UseCases/Team/TeamDetailUseCase.cs | 8 ++--- .../UseCases/Team/TeamMemberAppendUseCase.cs | 6 ++-- .../UseCases/Team/TeamMemberQueryUseCase.cs | 8 ++--- .../UseCases/Team/TeamMemberQuitUseCase.cs | 6 ++-- .../UseCases/Team/TeamMemberRemoveUseCase.cs | 6 ++-- .../UseCases/Team/TeamQueryUseCase.cs | 20 +++-------- .../UseCases/Team/TeamUpdateUseCase.cs | 6 ++-- .../Controllers/ConfigurationController.cs | 10 +++--- 44 files changed, 172 insertions(+), 217 deletions(-) diff --git a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs index 44fa235..1483476 100644 --- a/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Contracts/IConfigurationApplicationService.cs @@ -16,19 +16,21 @@ public interface IConfigurationApplicationService : IApplicationService /// 获取配置项列表 ///
/// + /// /// /// /// /// - Task> GetItemListAsync(string id, int skip, int count, CancellationToken cancellationToken = default); + Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default); /// /// 获取配置项数量 /// /// + /// /// /// - Task GetItemCountAsync(string id, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default); /// /// 获取配置详情 @@ -114,7 +116,6 @@ public interface IConfigurationApplicationService : IApplicationService /// 批量更新配置项 /// /// - /// /// /// /// diff --git a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs index efdf4ff..2217952 100644 --- a/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs +++ b/Source/Starfish.Service/Application/Implements/ConfigurationApplicationService.cs @@ -12,7 +12,7 @@ public class ConfigurationApplicationService : BaseApplicationService, IConfigur public Task> QueryAsync(ConfigurationCriteria criteria, int skip, int count, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new ConfigurationQueryInput(criteria, skip, count); + var input = new GenericQueryInput(criteria, skip, count); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } @@ -26,19 +26,19 @@ public Task CountAsync(ConfigurationCriteria criteria, CancellationToken ca } /// - public Task> GetItemListAsync(string id, 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(id, 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 id, CancellationToken cancellationToken = default) + public Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default) { var useCase = LazyServiceProvider.GetRequiredService(); - var input = new GetConfigurationItemCountInput(id); + var input = new GetConfigurationItemCountInput(id, key); return useCase.ExecuteAsync(input, cancellationToken) .ContinueWith(t => t.Result.Result, cancellationToken); } @@ -143,7 +143,7 @@ public Task GetItemsInTextAsync(string id, string format, CancellationTo { var parser = LazyServiceProvider.GetRequiredService() .GetKeyedService(format.Normalize(TextCaseType.Lower)); - return GetItemListAsync(id, 0, int.MaxValue, cancellationToken) + return GetItemListAsync(id, string.Empty, 0, int.MaxValue, cancellationToken) .ContinueWith(task => { task.WaitAndUnwrapException(cancellationToken); 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/Domain/Repositories/IConfigurationRepository.cs b/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs index 8a6f8c1..96bd4af 100644 --- a/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs +++ b/Source/Starfish.Service/Domain/Repositories/IConfigurationRepository.cs @@ -14,7 +14,7 @@ public interface IConfigurationRepository : IBaseRepository Task ExistsAsync(string teamId, string name, CancellationToken cancellationToken = default); - Task> GetItemListAsync(string id, int skip, int count, CancellationToken cancellationToken = default); + Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default); - Task GetItemCountAsync(string id, CancellationToken cancellationToken = default); + Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default); } \ 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 ee90a80..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; @@ -25,21 +26,45 @@ public Task ExistsAsync(string teamId, string name, CancellationToken canc return AnyAsync(predicate, null, cancellationToken); } - public Task> GetItemListAsync(string id, int skip, int count, CancellationToken cancellationToken = default) + public Task> GetItemListAsync(string id, string key, int skip, int count, CancellationToken cancellationToken = default) { var query = Context.Set() .AsQueryable() .AsNoTracking(); - return query.Where(t => t.ConfigurationId == id) + var expressions = new List>> + { + t=>t.ConfigurationId == id + }; + + if (!string.IsNullOrWhiteSpace(key)) + { + expressions.Add(t => t.Key.Contains(key)); + } + + var predicate = expressions.Compose(); + + return query.Where(predicate) .Skip(skip) .Take(count) .ToListAsync(cancellationToken); } - public Task GetItemCountAsync(string id, CancellationToken cancellationToken = default) + public Task GetItemCountAsync(string id, string key, CancellationToken cancellationToken = default) { var query = Context.Set() .AsQueryable(); - return query.Where(t => t.ConfigurationId == id).CountAsync(cancellationToken); + var expressions = new List>> + { + t=>t.ConfigurationId == id + }; + + if (!string.IsNullOrWhiteSpace(key)) + { + expressions.Add(t => t.Key.Contains(key)); + } + + var predicate = expressions.Compose(); + + return query.Where(predicate).CountAsync(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 27553ba..76f76ee 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationCreateUseCase.cs @@ -6,11 +6,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationCreateUseCase : IUseCase; +internal interface IConfigurationCreateUseCase : IUseCase; -public record ConfigurationCreateInput(string TeamId, ConfigurationEditDto Data) : IUseCaseInput; +internal record ConfigurationCreateInput(string TeamId, ConfigurationEditDto Data) : IUseCaseInput; -public class ConfigurationCreateUseCase : IConfigurationCreateUseCase +internal class ConfigurationCreateUseCase : IConfigurationCreateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs index 84a561d..ec4ff99 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationDeleteUseCase.cs @@ -7,18 +7,18 @@ namespace Nerosoft.Starfish.UseCases; /// /// 删除配置节点用例接口 /// -public interface IConfigurationDeleteUseCase : INonOutputUseCase; +internal interface IConfigurationDeleteUseCase : INonOutputUseCase; /// /// 删除配置节点输入 /// /// -public record ConfigurationDeleteInput(string Id) : IUseCaseInput; +internal record ConfigurationDeleteInput(string Id) : IUseCaseInput; /// /// 删除配置节点用例 /// -public class ConfigurationDeleteUseCase : IConfigurationDeleteUseCase +internal class ConfigurationDeleteUseCase : IConfigurationDeleteUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs index 50a9809..24f0492 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationItemsUpdateUseCase.cs @@ -5,11 +5,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationItemsUpdateUseCase : INonOutputUseCase; +internal interface IConfigurationItemsUpdateUseCase : INonOutputUseCase; -public record ConfigurationItemsUpdateInput(string Id, ConfigurationItemsUpdateDto Data); +internal record ConfigurationItemsUpdateInput(string Id, ConfigurationItemsUpdateDto Data); -public class ConfigurationItemsUpdateUseCase : IConfigurationItemsUpdateUseCase +internal class ConfigurationItemsUpdateUseCase : IConfigurationItemsUpdateUseCase { private readonly IBus _bus; private readonly IServiceProvider _provider; diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs index 01c6fb9..6ca5527 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationPublishUseCase.cs @@ -8,19 +8,19 @@ namespace Nerosoft.Starfish.UseCases; /// /// 配置节点发布用例接口 /// -public interface IConfigurationPublishUseCase : INonOutputUseCase; +internal interface IConfigurationPublishUseCase : INonOutputUseCase; /// /// 配置节点发布输入 /// /// /// -public record ConfigurationPublishInput(string Id, ConfigurationPublishRequestDto Data) : IUseCaseInput; +internal record ConfigurationPublishInput(string Id, ConfigurationPublishRequestDto Data) : IUseCaseInput; /// /// 配置节点发布用例 /// -public class ConfigurationPublishUseCase : IConfigurationPublishUseCase +internal class ConfigurationPublishUseCase : IConfigurationPublishUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs index 34acc1c..47edf02 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationQueryUseCase.cs @@ -5,9 +5,7 @@ namespace Nerosoft.Starfish.UseCases; -internal interface IConfigurationQueryUseCase : IUseCase; - -internal record ConfigurationQueryInput(ConfigurationCriteria Criteria, int Skip, int Count) : IUseCaseInput; +internal interface IConfigurationQueryUseCase : IUseCase, ConfigurationQueryOutput>; internal record ConfigurationQueryOutput(List Result) : IUseCaseOutput; @@ -20,7 +18,7 @@ public ConfigurationQueryUseCase(IConfigurationRepository repository) _repository = repository; } - public Task ExecuteAsync(ConfigurationQueryInput input, CancellationToken cancellationToken = default) + public Task ExecuteAsync(GenericQueryInput input, CancellationToken cancellationToken = default) { var specification = input.Criteria.GetSpecification(); var predicate = specification.Satisfy(); diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs index 553d88a..efb1fd3 100644 --- a/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/ConfigurationUpdateUseCase.cs @@ -6,11 +6,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface IConfigurationUpdateUseCase : INonOutputUseCase; +internal interface IConfigurationUpdateUseCase : INonOutputUseCase; -public record ConfigurationUpdateInput(string Id, ConfigurationEditDto Data); +internal record ConfigurationUpdateInput(string Id, ConfigurationEditDto Data); -public class ConfigurationUpdateUseCase : IConfigurationUpdateUseCase +internal class ConfigurationUpdateUseCase : IConfigurationUpdateUseCase { private readonly IBus _bus; diff --git a/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Configs/ConfigurationValueUpdateUseCase.cs index 193a035..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 Id, 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; diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs index 46a763d..f5698e2 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationArchiveUseCase.cs @@ -3,13 +3,13 @@ namespace Nerosoft.Starfish.UseCases; -public interface IGetConfigurationArchiveUseCase : IUseCase; +internal interface IGetConfigurationArchiveUseCase : IUseCase; -public record GetConfigurationArchiveOutput(string Result) : IUseCaseOutput; +internal record GetConfigurationArchiveOutput(string Result) : IUseCaseOutput; -public record GetConfigurationArchiveInput(string Id) : IUseCaseInput; +internal record GetConfigurationArchiveInput(string Id) : IUseCaseInput; -public class GetConfigurationArchiveUseCase : IGetConfigurationArchiveUseCase +internal class GetConfigurationArchiveUseCase : IGetConfigurationArchiveUseCase { private readonly IConfigurationRepository _repository; diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationDetailUseCase.cs index ed4de7d..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(ConfigurationDto Result) : IUseCaseOutput; +internal record GetConfigurationDetailOutput(ConfigurationDto Result) : IUseCaseOutput; /// /// 获取配置节点详情用例输入 /// /// -public record GetConfigurationDetailInput(string Id) : IUseCaseInput; +internal record GetConfigurationDetailInput(string Id) : IUseCaseInput; /// /// 获取配置节点详情用例 /// -public class GetConfigurationDetailUseCase : IGetConfigurationDetailUseCase +internal class GetConfigurationDetailUseCase : IGetConfigurationDetailUseCase { private readonly IConfigurationRepository _repository; diff --git a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs index f922e80..5abb5c5 100644 --- a/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/GetConfigurationItemCountUseCase.cs @@ -6,24 +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 Id) : IUseCaseInput; +/// +internal record GetConfigurationItemCountInput(string Id, string Key) : IUseCaseInput; /// /// 获取符合条件的配置数量用例 /// -public class GetConfigurationItemCountUseCase : IGetConfigurationItemCountUseCase +internal class GetConfigurationItemCountUseCase : IGetConfigurationItemCountUseCase { private readonly IConfigurationRepository _repository; @@ -39,7 +40,7 @@ public GetConfigurationItemCountUseCase(IConfigurationRepository repository) /// public Task ExecuteAsync(GetConfigurationItemCountInput input, CancellationToken cancellationToken = default) { - return _repository.GetItemCountAsync(input.Id, 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 2655401..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, 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, 0, 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/SetConfigurationSecretUseCase.cs b/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs index 4f03562..1b3704b 100644 --- a/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs +++ b/Source/Starfish.Service/UseCases/Configs/SetConfigurationSecretUseCase.cs @@ -4,11 +4,11 @@ namespace Nerosoft.Starfish.UseCases; -public interface ISetConfigurationSecretUseCase : INonOutputUseCase; +internal interface ISetConfigurationSecretUseCase : INonOutputUseCase; -public record SetConfigurationSecretInput(string Id, string Secret) : IUseCaseInput; +internal record SetConfigurationSecretInput(string Id, string Secret) : IUseCaseInput; -public class SetConfigurationSecretUseCase : ISetConfigurationSecretUseCase +internal class SetConfigurationSecretUseCase : ISetConfigurationSecretUseCase { private readonly IBus _bus; 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.Webapi/Controllers/ConfigurationController.cs b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs index 002d481..54cfea5 100644 --- a/Source/Starfish.Webapi/Controllers/ConfigurationController.cs +++ b/Source/Starfish.Webapi/Controllers/ConfigurationController.cs @@ -172,13 +172,14 @@ public async Task PushRedisAsync(string id, [FromBody] Configurat /// 获取配置项列表 /// /// 应用Id + /// /// /// /// /// [HttpGet("{id}/item")] [Produces(typeof(List))] - public async Task GetItemListAsync(string id, int skip = Constants.Query.Skip, int count = Constants.Query.Count, [FromHeader(Name = "x-format")] string format = null) + 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) { @@ -189,7 +190,7 @@ public async Task GetItemListAsync(string id, int skip = Constant var json = await _service.GetItemsInTextAsync(id, "json", HttpContext.RequestAborted); return Ok(json); default: - var result = await _service.GetItemListAsync(id, skip, count, HttpContext.RequestAborted); + var result = await _service.GetItemListAsync(id, key, skip, count, HttpContext.RequestAborted); return Ok(result); } } @@ -198,12 +199,13 @@ public async Task GetItemListAsync(string id, int skip = Constant /// 获取配置项数量 /// /// 应用Id + /// 关键字 /// [HttpGet("{id}/item/count")] [Produces(typeof(int))] - public async Task GetItemCountAsync(string id) + public async Task GetItemCountAsync(string id, string keyword) { - var result = await _service.GetItemCountAsync(id, HttpContext.RequestAborted); + var result = await _service.GetItemCountAsync(id, keyword, HttpContext.RequestAborted); return Ok(result); } From 0862d1325ad6a14133bacf310a4d782af7d14755 Mon Sep 17 00:00:00 2001 From: damon Date: Wed, 21 Feb 2024 23:50:07 +0800 Subject: [PATCH 26/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9Client=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/HttpConfigurationClient.cs | 10 ++++------ .../Clients/SocketConfigurationClient.cs | 4 ++-- .../Starfish.Client/ConfigurationClientOptions.cs | 14 ++++---------- .../StarfishConfigurationProvider.cs | 6 +++--- 4 files changed, 13 insertions(+), 21 deletions(-) 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