diff --git a/Source/Starfish.Service/Application/Commands/Setting/SettingAbstractCommand.cs b/Source/Starfish.Service/Application/Commands/Setting/SettingAbstractCommand.cs
index df84e22..5165ec1 100644
--- a/Source/Starfish.Service/Application/Commands/Setting/SettingAbstractCommand.cs
+++ b/Source/Starfish.Service/Application/Commands/Setting/SettingAbstractCommand.cs
@@ -16,7 +16,7 @@ protected SettingAbstractCommand(long appId, string environment)
public long AppId { get; set; }
///
- /// 环境名称
+ /// 应用环境
///
public string Environment { get; set; }
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Application/Commands/Setting/SettingArchiveCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Setting/SettingArchiveCreateCommand.cs
index 0af1e8e..1c92d77 100644
--- a/Source/Starfish.Service/Application/Commands/Setting/SettingArchiveCreateCommand.cs
+++ b/Source/Starfish.Service/Application/Commands/Setting/SettingArchiveCreateCommand.cs
@@ -8,7 +8,12 @@ namespace Nerosoft.Starfish.Application;
public class SettingArchiveCreateCommand : Command
{
///
- /// 配置根节点Id
+ /// 应用Id
///
- public long RootId { get; set; }
+ public long AppId { get; set; }
+
+ ///
+ /// 应用环境
+ ///
+ public string Environment { get; set; }
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Application/Commands/Setting/SettingRevisionCreateCommand.cs b/Source/Starfish.Service/Application/Commands/Setting/SettingRevisionCreateCommand.cs
index b91cde7..edb25fe 100644
--- a/Source/Starfish.Service/Application/Commands/Setting/SettingRevisionCreateCommand.cs
+++ b/Source/Starfish.Service/Application/Commands/Setting/SettingRevisionCreateCommand.cs
@@ -8,9 +8,9 @@ namespace Nerosoft.Starfish.Application;
public class SettingRevisionCreateCommand : Command
{
///
- /// 配置根节点Id
+ /// 应用Id
///
- public long SettingId { get; set; }
+ public long AppId { get; set; }
///
/// 说明
@@ -21,4 +21,9 @@ public class SettingRevisionCreateCommand : Command
/// 版本号
///
public string Version { get; set; }
+
+ ///
+ /// 应用环境
+ ///
+ public string Environment { get; set; }
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Application/Commands/Setting/SettingValueUpdateCommand.cs b/Source/Starfish.Service/Application/Commands/Setting/SettingValueUpdateCommand.cs
new file mode 100644
index 0000000..e68e6cb
--- /dev/null
+++ b/Source/Starfish.Service/Application/Commands/Setting/SettingValueUpdateCommand.cs
@@ -0,0 +1,17 @@
+namespace Nerosoft.Starfish.Application;
+
+public class SettingValueUpdateCommand : SettingAbstractCommand
+{
+ public SettingValueUpdateCommand(long appId, string environment, string key, string value)
+ : base(appId, environment)
+ {
+ AppId = appId;
+ Environment = environment;
+ Key = key;
+ Value = value;
+ }
+
+ public string Key { get; set; }
+
+ public string Value { get; set; }
+}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Application/Handlers/SettingArchiveCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/SettingArchiveCommandHandler.cs
index 7b06771..ebb6733 100644
--- a/Source/Starfish.Service/Application/Handlers/SettingArchiveCommandHandler.cs
+++ b/Source/Starfish.Service/Application/Handlers/SettingArchiveCommandHandler.cs
@@ -20,7 +20,7 @@ public Task HandleAsync(SettingArchiveCreateCommand message, MessageContext cont
{
return ExecuteAsync(async () =>
{
- var (appId, appCode, environment, items) = await GetItemsAsync(message.RootId, cancellationToken);
+ var (appId, appCode, environment, items) = await GetItemsAsync(message.AppId, message.Environment, cancellationToken);
var data = items.ToDictionary(t => t.Key, t => t.Value);
var json = JsonConvert.SerializeObject(data);
@@ -30,15 +30,15 @@ public Task HandleAsync(SettingArchiveCreateCommand message, MessageContext cont
});
}
- private async Task>> GetItemsAsync(long id, CancellationToken cancellationToken = default)
+ private async Task>> GetItemsAsync(long appId, string environment, CancellationToken cancellationToken = default)
{
var repository = UnitOfWork.Current.GetService();
- var aggregate = await repository.GetAsync(id, false, [nameof(Setting.Items)], cancellationToken);
+ var aggregate = await repository.GetAsync(appId, environment, false, [nameof(Setting.Items)], cancellationToken);
if (aggregate == null)
{
- throw new SettingNotFoundException(id);
+ throw new SettingNotFoundException(appId, environment);
}
return Tuple.Create(aggregate.AppId, aggregate.AppCode, aggregate.Environment, aggregate.Items.ToList());
diff --git a/Source/Starfish.Service/Application/Handlers/SettingCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/SettingCommandHandler.cs
index 1098204..02f1788 100644
--- a/Source/Starfish.Service/Application/Handlers/SettingCommandHandler.cs
+++ b/Source/Starfish.Service/Application/Handlers/SettingCommandHandler.cs
@@ -13,7 +13,8 @@ public class SettingCommandHandler : CommandHandlerBase,
IHandler,
IHandler,
IHandler,
- IHandler
+ IHandler,
+ IHandler
{
public SettingCommandHandler(IUnitOfWorkManager unitOfWork, IObjectFactory factory)
: base(unitOfWork, factory)
@@ -62,4 +63,15 @@ public Task HandleAsync(SettingPublishCommand message, MessageContext context, C
await Factory.ExecuteAsync(message.AppId, message.Environment, cancellationToken);
});
}
+
+ public Task HandleAsync(SettingValueUpdateCommand message, MessageContext context, CancellationToken cancellationToken = default)
+ {
+ return ExecuteAsync(async () =>
+ {
+ var business = await Factory.FetchAsync(message.AppId, message.Environment, cancellationToken);
+ business.Key = message.Key;
+ business.Value = message.Value;
+ _ = await business.SaveAsync(true, cancellationToken);
+ });
+ }
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Application/Handlers/SettingRevisionCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/SettingRevisionCommandHandler.cs
index 074cd15..fa48bc0 100644
--- a/Source/Starfish.Service/Application/Handlers/SettingRevisionCommandHandler.cs
+++ b/Source/Starfish.Service/Application/Handlers/SettingRevisionCommandHandler.cs
@@ -20,11 +20,11 @@ public Task HandleAsync(SettingRevisionCreateCommand message, MessageContext con
{
var repository = UnitOfWork.Current.GetService();
- var aggregate = await repository.GetAsync(message.SettingId, false, [nameof(Setting.Items), nameof(Setting.Revisions)], cancellationToken);
+ var aggregate = await repository.GetAsync(message.AppId, message.Environment, false, [nameof(Setting.Items), nameof(Setting.Revisions)], cancellationToken);
if (aggregate == null)
{
- throw new SettingNotFoundException(message.SettingId);
+ throw new SettingNotFoundException(message.AppId, message.Environment);
}
aggregate.CreateRevision(message.Version, message.Comment, context.User?.Identity?.Name);
diff --git a/Source/Starfish.Service/Application/Implements/SettingApplicationService.cs b/Source/Starfish.Service/Application/Implements/SettingApplicationService.cs
index a2407e1..7feb0b9 100644
--- a/Source/Starfish.Service/Application/Implements/SettingApplicationService.cs
+++ b/Source/Starfish.Service/Application/Implements/SettingApplicationService.cs
@@ -41,7 +41,7 @@ public Task GetDetailAsync(long appId, string environment, Can
public Task CreateAsync(long appId, string environment, string format, SettingEditDto data, CancellationToken cancellationToken = default)
{
var useCase = LazyServiceProvider.GetRequiredService();
- var input = new SettingCreateInput(appId, environment,format, data);
+ var input = new SettingCreateInput(appId, environment, format, data);
return useCase.ExecuteAsync(input, cancellationToken)
.ContinueWith(t => t.Result, cancellationToken);
}
@@ -63,7 +63,9 @@ public Task DeleteAsync(long appId, string environment, CancellationToken cancel
public Task UpdateAsync(long appId, string environment, string key, string value, CancellationToken cancellationToken = default)
{
- throw new NotImplementedException();
+ var useCase = LazyServiceProvider.GetRequiredService();
+ var input = new SettingValueUpdateInput(appId, environment, key, value);
+ return useCase.ExecuteAsync(input, cancellationToken);
}
///
diff --git a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs
index 3b22c35..7c804e5 100644
--- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs
+++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.cs
@@ -9,29 +9,27 @@ namespace Nerosoft.Starfish.Application;
public sealed class LoggingEventSubscriber
{
private readonly IBus _bus;
- private readonly IServiceProvider _provider;
- public LoggingEventSubscriber(IBus bus, IServiceProvider provider)
+ public LoggingEventSubscriber(IBus bus)
{
_bus = bus;
- _provider = provider;
}
///
/// 处理用户认证成功事件
///
- ///
+ ///
///
///
///
[Subscribe]
- public Task HandleAsync(UserAuthSucceedEvent message, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(UserAuthSucceedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var command = new OperateLogCreateCommand
{
Module = "auth",
- Type = message.AuthType,
- UserName = message.UserName,
+ Type = @event.AuthType,
+ UserName = @event.UserName,
OperateTime = DateTime.Now,
Description = Resources.IDS_MESSAGE_LOGS_AUTH_SUCCEED,
RequestTraceId = context.RequestTraceId
@@ -42,21 +40,21 @@ public Task HandleAsync(UserAuthSucceedEvent message, MessageContext context, Ca
///
/// 处理用户认证失败事件
///
- ///
+ ///
///
///
///
[Subscribe]
- public Task HandleAsync(UserAuthFailedEvent message, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(UserAuthFailedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var command = new OperateLogCreateCommand
{
Module = "auth",
- Type = message.AuthType,
+ Type = @event.AuthType,
Description = Resources.IDS_MESSAGE_LOGS_AUTH_FAILED,
OperateTime = DateTime.Now,
RequestTraceId = context.RequestTraceId,
- Error = message.Error
+ Error = @event.Error
};
return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
@@ -65,13 +63,13 @@ public Task HandleAsync(UserAuthFailedEvent message, MessageContext context, Can
///
/// 处理应用创建事件
///
- ///
+ ///
///
///
[Subscribe]
- public Task HandleAsync(AppInfoCreatedEvent message, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(AppInfoCreatedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
- var aggregate = message.GetAggregate();
+ var aggregate = @event.GetAggregate();
var command = new OperateLogCreateCommand
{
Module = "apps",
@@ -88,14 +86,14 @@ public Task HandleAsync(AppInfoCreatedEvent message, MessageContext context, Can
///
/// 处理应用启用事件
///
- ///
+ ///
///
///
///
[Subscribe]
- public Task HandleAsync(AppInfoEnabledEvent message, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(AppInfoEnabledEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
- var aggregate = message.GetAggregate();
+ var aggregate = @event.GetAggregate();
var command = new OperateLogCreateCommand
{
Module = "apps",
@@ -112,14 +110,14 @@ public Task HandleAsync(AppInfoEnabledEvent message, MessageContext context, Can
///
/// 处理应用禁用事件
///
- ///
+ ///
///
///
///
[Subscribe]
- public Task HandleAsync(AppInfoDisableEvent message, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(AppInfoDisableEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
- var aggregate = message.GetAggregate();
+ var aggregate = @event.GetAggregate();
var command = new OperateLogCreateCommand
{
Module = "appinfo",
@@ -183,12 +181,9 @@ public Task HandleAsync(SettingDeletedEvent @event, MessageContext context, Canc
}
[Subscribe]
- public async Task HandleAsync(SettingPublishedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
+ public Task HandleAsync(SettingPublishedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
- var repository = _provider.GetService();
- var setting = await repository.GetAsync(@event.AppId, false, [], cancellationToken);
-
- var description = string.Format(Resources.IDS_MESSAGE_LOGS_SETTING_PUBLISH, setting.AppId, setting.Environment);
+ var description = string.Format(Resources.IDS_MESSAGE_LOGS_SETTING_PUBLISH, @event.AppId, @event.Environment);
var command = new OperateLogCreateCommand
{
@@ -199,6 +194,6 @@ public async Task HandleAsync(SettingPublishedEvent @event, MessageContext conte
RequestTraceId = context.RequestTraceId,
UserName = context.User?.Identity?.Name
};
- await _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
+ 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/SettingArchiveEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/SettingArchiveEventSubscriber.cs
index fb8a405..f3f01c6 100644
--- a/Source/Starfish.Service/Application/Subscribers/SettingArchiveEventSubscriber.cs
+++ b/Source/Starfish.Service/Application/Subscribers/SettingArchiveEventSubscriber.cs
@@ -26,7 +26,8 @@ public Task HandleAsync(SettingPublishedEvent message, MessageContext context, C
{
var command = new SettingArchiveCreateCommand
{
- RootId = message.AppId
+ AppId = message.AppId,
+ Environment = message.Environment,
};
return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
diff --git a/Source/Starfish.Service/Application/Subscribers/SettingRevisionEventSubscriber.cs b/Source/Starfish.Service/Application/Subscribers/SettingRevisionEventSubscriber.cs
index 45d9c68..4a5e2e8 100644
--- a/Source/Starfish.Service/Application/Subscribers/SettingRevisionEventSubscriber.cs
+++ b/Source/Starfish.Service/Application/Subscribers/SettingRevisionEventSubscriber.cs
@@ -26,7 +26,8 @@ public Task HandleAsync(SettingPublishedEvent message, MessageContext context, C
{
var command = new SettingRevisionCreateCommand
{
- SettingId = message.AppId,
+ AppId = message.AppId,
+ Environment = message.Environment,
Version = message.Version,
Comment = message.Comment
};
diff --git a/Source/Starfish.Service/Domain/Aggregates/Setting.cs b/Source/Starfish.Service/Domain/Aggregates/Setting.cs
index a57b2b6..79b6ca1 100644
--- a/Source/Starfish.Service/Domain/Aggregates/Setting.cs
+++ b/Source/Starfish.Service/Domain/Aggregates/Setting.cs
@@ -28,7 +28,7 @@ private Setting()
public string AppCode { get; set; }
///
- /// 环境名称
+ /// 应用环境
///
public string Environment { get; set; }
@@ -113,6 +113,27 @@ internal void AddOrUpdateItem(IDictionary items)
Status = SettingStatus.Pending;
}
+ internal void UpdateItem(string key, string value)
+ {
+ if (Status == SettingStatus.Disabled)
+ {
+ throw new InvalidOperationException(Resources.IDS_ERROR_SETTING_DISABLED);
+ }
+
+ Items ??= [];
+
+ var item = Items.FirstOrDefault(t => string.Equals(t.Key, key));
+
+ if (item == null)
+ {
+ throw new InvalidOperationException(string.Format(Resources.IDS_ERROR_SETTING_KEY_NOT_EXISTS, key));
+ }
+
+ item.Value = value;
+
+ Status = SettingStatus.Pending;
+ }
+
internal void SetStatus(SettingStatus status)
{
if (Status == status)
diff --git a/Source/Starfish.Service/Domain/Business/SettingGeneralBusiness.cs b/Source/Starfish.Service/Domain/Business/SettingGeneralBusiness.cs
index bcb2b0c..e24a5cd 100644
--- a/Source/Starfish.Service/Domain/Business/SettingGeneralBusiness.cs
+++ b/Source/Starfish.Service/Domain/Business/SettingGeneralBusiness.cs
@@ -19,6 +19,8 @@ internal class SettingGeneralBusiness : EditableObjectBase 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
{
@@ -44,6 +46,18 @@ public IDictionary Items
set => SetProperty(ItemsProperty, value);
}
+ public string Key
+ {
+ get => GetProperty(KeyProperty);
+ set => SetProperty(KeyProperty, value);
+ }
+
+ public string Value
+ {
+ get => GetProperty(ValueProperty);
+ set => SetProperty(ValueProperty, value);
+ }
+
protected override void AddRules()
{
Rules.AddRule(new DuplicateCheckRule());
@@ -58,9 +72,9 @@ protected override async Task CreateAsync(CancellationToken cancellationToken =
[FactoryFetch]
protected async Task FetchAsync(long appId, string environment, CancellationToken cancellationToken = default)
{
- var aggregate = await SettingRepository.GetAsync(appId, environment, false, Array.Empty(), cancellationToken);
+ var aggregate = await SettingRepository.GetAsync(appId, environment, true, [nameof(Setting.Items)], cancellationToken);
- Aggregate = aggregate ?? throw new SettingNotFoundException(appId);
+ Aggregate = aggregate ?? throw new SettingNotFoundException(appId, environment);
using (BypassRuleChecks)
{
@@ -91,6 +105,10 @@ protected override async Task UpdateAsync(CancellationToken cancellationToken =
{
Aggregate.AddOrUpdateItem(Items);
}
+ else if (ChangedProperties.Contains(KeyProperty) && ChangedProperties.Contains(ValueProperty))
+ {
+ Aggregate.UpdateItem(Key, Value);
+ }
await SettingRepository.UpdateAsync(Aggregate, true, cancellationToken);
}
diff --git a/Source/Starfish.Service/Domain/Business/SettingPublishBusiness.cs b/Source/Starfish.Service/Domain/Business/SettingPublishBusiness.cs
index 3037d89..3cb9cd3 100644
--- a/Source/Starfish.Service/Domain/Business/SettingPublishBusiness.cs
+++ b/Source/Starfish.Service/Domain/Business/SettingPublishBusiness.cs
@@ -24,17 +24,17 @@ protected async Task ExecuteAsync(long appId, string environment, CancellationTo
if (aggregate == null)
{
- throw new SettingNotFoundException(appId);
+ throw new SettingNotFoundException(appId, environment);
}
if (aggregate == null)
{
- throw new SettingNotFoundException(appId);
+ throw new SettingNotFoundException(appId, environment);
}
if (aggregate.Status == SettingStatus.Disabled)
{
- throw new SettingDisabledException(appId);
+ throw new SettingDisabledException(appId, environment);
}
aggregate.SetStatus(SettingStatus.Published);
diff --git a/Source/Starfish.Service/Domain/Business/TeamGeneralBusiness.cs b/Source/Starfish.Service/Domain/Business/TeamGeneralBusiness.cs
index fa15874..5dd8fd3 100644
--- a/Source/Starfish.Service/Domain/Business/TeamGeneralBusiness.cs
+++ b/Source/Starfish.Service/Domain/Business/TeamGeneralBusiness.cs
@@ -58,7 +58,7 @@ protected async Task FetchAsync(int id, CancellationToken cancellationToken = de
{
var aggregate = await TeamRepository.GetAsync(id, true, [], cancellationToken);
- Aggregate = aggregate ?? throw new SettingNotFoundException(id);
+ Aggregate = aggregate ?? throw new TeamNotFoundException(id);
using (BypassRuleChecks)
{
diff --git a/Source/Starfish.Service/Domain/Business/TeamMemberBusiness.cs b/Source/Starfish.Service/Domain/Business/TeamMemberBusiness.cs
index 3736501..1b69129 100644
--- a/Source/Starfish.Service/Domain/Business/TeamMemberBusiness.cs
+++ b/Source/Starfish.Service/Domain/Business/TeamMemberBusiness.cs
@@ -34,7 +34,7 @@ protected async Task FetchAsync(int id, CancellationToken cancellationToken = de
{
var aggregate = await TeamRepository.GetAsync(id, true, [nameof(Team.Members)], cancellationToken);
- Aggregate = aggregate ?? throw new SettingNotFoundException(id);
+ Aggregate = aggregate ?? throw new TeamNotFoundException(id);
}
[FactoryInsert]
diff --git a/Source/Starfish.Service/Domain/Exceptions/SettingDisabledException.cs b/Source/Starfish.Service/Domain/Exceptions/SettingDisabledException.cs
index 41b69e9..097b378 100644
--- a/Source/Starfish.Service/Domain/Exceptions/SettingDisabledException.cs
+++ b/Source/Starfish.Service/Domain/Exceptions/SettingDisabledException.cs
@@ -2,8 +2,8 @@
public class SettingDisabledException : BadRequestException
{
- public SettingDisabledException(long id)
- : base(string.Format(Resources.IDS_ERROR_SETTING_DISABLED, id))
+ public SettingDisabledException(long appId, string environment)
+ : base(string.Format(Resources.IDS_ERROR_SETTING_DISABLED, appId, environment))
{
}
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Domain/Exceptions/SettingNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/SettingNotFoundException.cs
index 3caacd8..b386edb 100644
--- a/Source/Starfish.Service/Domain/Exceptions/SettingNotFoundException.cs
+++ b/Source/Starfish.Service/Domain/Exceptions/SettingNotFoundException.cs
@@ -8,9 +8,10 @@ public class SettingNotFoundException : NotFoundException
///
/// 构造函数
///
- ///
- public SettingNotFoundException(long id)
- : base(string.Format(Resources.IDS_ERROR_SETTING_NOT_EXISTS, id))
+ /// 应用Id
+ /// 应用环境
+ public SettingNotFoundException(long appId, string environment)
+ : base(string.Format(Resources.IDS_ERROR_SETTING_NOT_EXISTS, appId, environment))
{
}
}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Domain/Exceptions/TeamNotFoundException.cs b/Source/Starfish.Service/Domain/Exceptions/TeamNotFoundException.cs
new file mode 100644
index 0000000..536be5c
--- /dev/null
+++ b/Source/Starfish.Service/Domain/Exceptions/TeamNotFoundException.cs
@@ -0,0 +1,9 @@
+namespace Nerosoft.Starfish.Domain;
+
+public class TeamNotFoundException : NotFoundException
+{
+ public TeamNotFoundException(int id)
+ : base(string.Format(Resources.IDS_ERROR_TEAM_NOT_EXISTS, id))
+ {
+ }
+}
\ No newline at end of file
diff --git a/Source/Starfish.Service/Domain/Repositories/ISettingRepository.cs b/Source/Starfish.Service/Domain/Repositories/ISettingRepository.cs
index ae120d9..a5bf8c8 100644
--- a/Source/Starfish.Service/Domain/Repositories/ISettingRepository.cs
+++ b/Source/Starfish.Service/Domain/Repositories/ISettingRepository.cs
@@ -14,16 +14,6 @@ public interface ISettingRepository : IRepository
///
Task ExistsAsync(long appId, string environment, CancellationToken cancellationToken = default);
- ///
- /// 获取指定配置
- ///
- ///
- ///
- ///
- ///
- ///
- Task GetAsync(long id, bool tracking, string[] properties, CancellationToken cancellationToken = default);
-
Task GetAsync(long appId, string environment, bool tracking, string[] properties, CancellationToken cancellationToken = default);
Task GetAsync(Expression> predicate, bool tracking, string[] properties, CancellationToken cancellationToken = default);
diff --git a/Source/Starfish.Service/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx
index 5be4f78..e6435a9 100644
--- a/Source/Starfish.Service/Properties/Resources.resx
+++ b/Source/Starfish.Service/Properties/Resources.resx
@@ -217,7 +217,7 @@
Data format required.
- Setting was disabled, [Id]:{0}.
+ Setting was disabled, [App]:{0}, [Env]:{1}.
Setting was duplicated, [App]:{0}, [Env]:{1}.
@@ -225,8 +225,11 @@
Setting key '{0}' exists.
+
+ Setting key '{0}' not exists.
+
- Setting not exists, [Id]:{0}.
+ Setting not exists, [App]:{0}, [Env]:{1}.
No pending item to publish.
@@ -234,6 +237,9 @@
Version number '{0}' already exists.
+
+ Team not exists, [Id]:{0}.
+
Only allowed team owner to add/remove team member.
diff --git a/Source/Starfish.Service/Properties/Resources.zh-CN.resx b/Source/Starfish.Service/Properties/Resources.zh-CN.resx
index e89fe84..75120e3 100644
--- a/Source/Starfish.Service/Properties/Resources.zh-CN.resx
+++ b/Source/Starfish.Service/Properties/Resources.zh-CN.resx
@@ -217,16 +217,19 @@
数据格式不能为空。
- 配置已被禁用,[Id]:{0}。
+ 配置已被禁用,[应用]:{0},[环境]:{1}。
配置重复,[应用]:{0},[环境]:{1}。
- 配置Key '{0}' 已经存在。
+ 配置项 '{0}' 已经存在。
+
+
+ 配置项 '{0}' 不存在。
- 配置不存在,[Id]:{0}。
+ 配置不存在,[应用]:{0},[环境]:{1}。
没有待发布的配置。
@@ -234,6 +237,9 @@
版本号 '{0}' 已经存在。
+
+ 团队不存在,[Id]:{0}。
+
仅允许团队负责人添加/移除团队成员。
diff --git a/Source/Starfish.Service/Repository/Contexts/SqliteModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/SqliteModelBuilder.cs
index 3c897e5..cdac417 100644
--- a/Source/Starfish.Service/Repository/Contexts/SqliteModelBuilder.cs
+++ b/Source/Starfish.Service/Repository/Contexts/SqliteModelBuilder.cs
@@ -123,7 +123,7 @@ public void Configure(ModelBuilder modelBuilder)
.HasValueGenerator();
entity.HasOne(t => t.Setting)
- .WithMany()
+ .WithMany(t => t.Revisions)
.HasForeignKey(t => t.SettingId)
.OnDelete(DeleteBehavior.Cascade);
});
diff --git a/Source/Starfish.Service/UseCases/Setting/SettingValueUpdateUseCase.cs b/Source/Starfish.Service/UseCases/Setting/SettingValueUpdateUseCase.cs
new file mode 100644
index 0000000..f175479
--- /dev/null
+++ b/Source/Starfish.Service/UseCases/Setting/SettingValueUpdateUseCase.cs
@@ -0,0 +1,29 @@
+using Nerosoft.Euonia.Application;
+using Nerosoft.Euonia.Bus;
+using Nerosoft.Starfish.Application;
+
+namespace Nerosoft.Starfish.UseCases;
+
+public interface ISettingValueUpdateUseCase : INonOutputUseCase;
+
+public record SettingValueUpdateInput(long AppId, string Environment, string Key, string Value) : IUseCaseInput;
+
+public class SettingValueUpdateUseCase : ISettingValueUpdateUseCase
+{
+ private readonly IBus _bus;
+
+ public SettingValueUpdateUseCase(IBus bus)
+ {
+ _bus = bus;
+ }
+
+ public Task ExecuteAsync(SettingValueUpdateInput input, CancellationToken cancellationToken = default)
+ {
+ var command = new SettingValueUpdateCommand(input.AppId, input.Environment, input.Key, input.Value);
+ return _bus.SendAsync(command, cancellationToken)
+ .ContinueWith(task =>
+ {
+ task.WaitAndUnwrapException(cancellationToken);
+ }, cancellationToken);
+ }
+}
\ No newline at end of file
diff --git a/Source/Starfish.Transit/Setting/SettingValueUpdateDto.cs b/Source/Starfish.Transit/Setting/SettingValueUpdateDto.cs
new file mode 100644
index 0000000..9b135f4
--- /dev/null
+++ b/Source/Starfish.Transit/Setting/SettingValueUpdateDto.cs
@@ -0,0 +1,12 @@
+namespace Nerosoft.Starfish.Transit;
+
+///
+/// 配置项更新Dto
+///
+public class SettingValueUpdateDto
+{
+ ///
+ ///
+ ///
+ public string Value { get; set; }
+}
\ No newline at end of file
diff --git a/Source/Starfish.Webapi/Controllers/SettingController.cs b/Source/Starfish.Webapi/Controllers/SettingController.cs
index e723b1c..289a913 100644
--- a/Source/Starfish.Webapi/Controllers/SettingController.cs
+++ b/Source/Starfish.Webapi/Controllers/SettingController.cs
@@ -28,8 +28,8 @@ public SettingController(ISettingApplicationService service)
///
/// 获取配置项列表
///
- ///
- ///
+ /// 应用Id
+ /// 应用环境
///
///
///
@@ -55,8 +55,8 @@ public async Task GetItemListAsync(long id, string environment, i
///
/// 获取配置项数量
///
- ///
- ///
+ /// 应用Id
+ /// 应用环境
///
[HttpGet("item/count")]
[Produces(typeof(int))]
@@ -69,8 +69,8 @@ public async Task GetItemCountAsync(long id, string environment)
///
/// 获取Json格式配置
///
- ///
- ///
+ /// 应用Id
+ /// 应用环境
///
[HttpGet("item/json")]
[Produces(typeof(string))]
@@ -84,7 +84,7 @@ public async Task GetJsonAsync(long id, string environment)
/// 获取配置节点详情
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
///
[HttpGet("detail")]
public async Task GetAsync(long id, string environment)
@@ -97,7 +97,7 @@ public async Task GetAsync(long id, string environment)
/// 新增配置
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
///
///
///
@@ -113,7 +113,7 @@ public async Task CreateAsync(long id, string environment, [FromH
/// 更新配置
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
/// 数据格式
/// 数据内容
///
@@ -128,7 +128,7 @@ public async Task UpdateAsync(long id, string environment, [FromH
/// 删除配置
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
///
[HttpDelete]
public async Task DeleteAsync(long id, string environment)
@@ -141,16 +141,15 @@ public async Task DeleteAsync(long id, string environment)
/// 更新配置项的值
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
/// 完整Key名称
- ///
+ ///
///
[HttpPut("{key}")]
- [Consumes("plain/text")]
- public async Task UpdateItemValueAsync(long id, string environment, string key, [FromBody] string value)
+ public async Task UpdateItemValueAsync(long id, string environment, string key, [FromBody] SettingValueUpdateDto data)
{
key = HttpUtility.UrlDecode(key);
- await _service.UpdateAsync(id, environment, key, value, HttpContext.RequestAborted);
+ await _service.UpdateAsync(id, environment, key, data.Value, HttpContext.RequestAborted);
return Ok();
}
@@ -158,7 +157,7 @@ public async Task UpdateItemValueAsync(long id, string environmen
/// 发布配置
///
/// 应用Id
- /// 配置环境
+ /// 应用环境
///
///
[HttpPost("publish")]
@@ -167,4 +166,17 @@ public async Task PublishAsync(long id, string environment, [From
await _service.PublishAsync(id, environment, data, HttpContext.RequestAborted);
return Ok();
}
+
+ ///
+ /// 获取发布的配置
+ ///
+ /// 应用Id
+ /// 应用环境
+ ///
+ [HttpGet("archive")]
+ public async Task GetArchivedAsync(long id, string environment)
+ {
+ var result = await _service.GetSettingRawAsync(id, environment, HttpContext.RequestAborted);
+ return Ok(result);
+ }
}
\ No newline at end of file
diff --git a/Source/Starfish.Webapp/Rest/Defines/ISettingApi.cs b/Source/Starfish.Webapp/Rest/Defines/ISettingApi.cs
index 470f18c..44289ef 100644
--- a/Source/Starfish.Webapp/Rest/Defines/ISettingApi.cs
+++ b/Source/Starfish.Webapp/Rest/Defines/ISettingApi.cs
@@ -27,9 +27,12 @@ internal interface ISettingApi
[Delete("/api/apps/{id}/setting/{environment}")]
Task DeleteAsync(long id, string environment, CancellationToken cancellationToken = default);
- [Put("/api/apps/{id}/setting/{environment}/item/{key}")]
- Task UpdateItemValueAsync(long id, string environment, string key, [Body] string value, CancellationToken cancellationToken = default);
+ [Put("/api/apps/{id}/setting/{environment}/{key}")]
+ Task UpdateItemValueAsync(long id, string environment, string key, [Body] SettingValueUpdateDto data, CancellationToken cancellationToken = default);
- [Post("/api/apps/{id}/setting/{environment}/item/publish")]
+ [Post("/api/apps/{id}/setting/{environment}/publish")]
Task PublishAsync(long id, string environment, [Body] SettingPublishDto data, CancellationToken cancellationToken = default);
+
+ [Get("/api/apps/{id}/setting/{environment}/archive")]
+ Task> GetArchivedAsync(long id, string environment, CancellationToken cancellationToken = default);
}
\ No newline at end of file