diff --git a/Directory.Build.props b/Directory.Build.props index 51099439..8a65bc83 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.2.0-preview.2 - 1.2.1-preview.4 + 1.2.0-preview.4 + 1.2.1-preview.8 \ No newline at end of file diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/App.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/App.cs new file mode 100644 index 00000000..6ac51919 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/App.cs @@ -0,0 +1,38 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[NotMapped] +public class App +{ + public int Id { get; set; } + + public string Name { get; set; } = ""; + + public string Identity { get; set; } = ""; + + public AppTypes Type { get; set; } + + public ServiceTypes ServiceType { get; set; } + + public string Url { get; set; } = ""; + + public string SwaggerUrl { get; set; } = ""; + + public string Description { get; set; } = ""; + + public DateTime CreationTime { get; set; } + + public Guid Creator { get; set; } + + public DateTime ModificationTime { get; set; } + + public Guid Modifier { get; set; } + + private readonly List _appConfigObjects = new(); + public IReadOnlyCollection AppConfigObjects => _appConfigObjects; + + private readonly List _appSecrets = new(); + public IReadOnlyCollection AppSecrets => _appSecrets; +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppConfigObject.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppConfigObject.cs new file mode 100644 index 00000000..07020181 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppConfigObject.cs @@ -0,0 +1,19 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("AppConfigObjects")] +public class AppConfigObject : ConfigObjectBase +{ + [Comment("AppId")] + [Required] + [Range(1, int.MaxValue)] + public int AppId { get; private set; } + + public AppConfigObject(int appId, int environmentClusterId) + { + EnvironmentClusterId = environmentClusterId; + AppId = appId; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppPin.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppPin.cs new file mode 100644 index 00000000..b6df4494 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppPin.cs @@ -0,0 +1,16 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +public class AppPin : FullAggregateRoot +{ + [Required] + [Range(1, int.MaxValue)] + public int AppId { get; set; } + + public AppPin(int appId) + { + AppId = appId; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppSecret.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppSecret.cs new file mode 100644 index 00000000..516aec46 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/AppSecret.cs @@ -0,0 +1,26 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("AppSecrets")] +public class AppSecret : FullAggregateRoot +{ + [Required] + [Range(1, int.MaxValue)] + public int AppId { get; private set; } + + [Required] + [Range(1, int.MaxValue)] + public int EnvironmentId { get; private set; } + + [Required] + [Range(1, int.MaxValue)] + public SecretType Type { get; private set; } + + [Required] + public Guid EncryptionSecret { get; private set; } + + [Required] + public Guid Secret { get; private set; } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfig.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfig.cs new file mode 100644 index 00000000..2e14eea4 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfig.cs @@ -0,0 +1,28 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("BizConfigs")] +public class BizConfig : FullAggregateRoot +{ + [Required] + public string Name { get; private set; } + + [Required] + public string Identity { get; private set; } + + private readonly List _bizConfigObjects = new(); + public IReadOnlyCollection BizConfigObjects => _bizConfigObjects; + + public BizConfig(string name, string identity) + { + Name = name; + Identity = identity; + } + + public void Update(string name) + { + Name = name; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfigObject.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfigObject.cs new file mode 100644 index 00000000..f9ba328c --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/BizConfigObject.cs @@ -0,0 +1,20 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("BizConfigObjects")] +public class BizConfigObject : ConfigObjectBase +{ + [Required] + [Range(1, int.MaxValue)] + public int BizConfigId { get; private set; } + + public BizConfig BizConfig { get; private set; } = null!; + + public BizConfigObject(int bizConfigId, int environmentClusterId) + { + BizConfigId = bizConfigId; + EnvironmentClusterId = environmentClusterId; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObject.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObject.cs new file mode 100644 index 00000000..a7592f7f --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObject.cs @@ -0,0 +1,116 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("ConfigObjects")] +public class ConfigObject : FullAggregateRoot +{ + [Comment("Name")] + [Required(ErrorMessage = "Config object name is required")] + [StringLength(100, MinimumLength = 2, ErrorMessage = "Config object name length range is [2-100]")] + public string Name { get; private set; } + + [Comment("Format")] + [Required(ErrorMessage = "Format Label Code is required")] + [StringLength(100, MinimumLength = 2, ErrorMessage = "Format Label Code length range is [2-100]")] + public string FormatLabelCode { get; private set; } + + [Comment("Type")] + [Range(1, int.MaxValue, ErrorMessage = "Type is required")] + public ConfigObjectType Type { get; private set; } + + [Required] + public bool Encryption { get; private set; } + + [Required] + public string Content { get; private set; } + + [Required] + public string TempContent { get; private set; } + + [Comment("Relation config object Id")] + public int RelationConfigObjectId { get; private set; } + + public bool FromRelation { get; private set; } + + public PublicConfigObject PublicConfigObject { get; private set; } = null!; + + public BizConfigObject BizConfigObject { get; set; } = null!; + + public AppConfigObject AppConfigObject { get; private set; } = null!; + + private readonly List _configObjectRelease = new(); + public IReadOnlyCollection ConfigObjectRelease => _configObjectRelease; + + public ConfigObject(string name, string formatLabelCode, ConfigObjectType type, string content, string tempContent, int relationConfigObjectId = 0, bool fromRelation = false, bool encryption = false) + { + Name = name; + FormatLabelCode = formatLabelCode; + Type = type; + Content = content; + TempContent = tempContent; + RelationConfigObjectId = relationConfigObjectId; + FromRelation = fromRelation; + Encryption = encryption; + } + + public void SetConfigObjectType(ConfigObjectType type) + { + Type = type; + } + + public void SetConfigObjectRelease(IEnumerable configObjectReleases) + { + _configObjectRelease.Clear(); + _configObjectRelease.TryAddRange(configObjectReleases); + } + + public void SetConfigObjectRelease(ConfigObjectRelease configObjectRelease) + { + _configObjectRelease.Clear(); + _configObjectRelease.TryAdd(configObjectRelease); + } + + public void UpdateContent(string content) + { + Content = content; + } + + public void AddContent(string content, string tempContent) + { + Content = content; + TempContent = tempContent; + } + + public void SetPublicConfigObject(int publicConfigId, int environmentClusterId) + { + PublicConfigObject = new PublicConfigObject(publicConfigId, environmentClusterId); + } + + public void SetBizConfigObject(int bizId, int environmentClusterId) + { + BizConfigObject = new BizConfigObject(bizId, environmentClusterId); + } + + public void SetAppConfigObject(int appId, int environmentClusterId) + { + AppConfigObject = new AppConfigObject(appId, environmentClusterId); + } + + public void Revoke() + { + Content = TempContent; + } + + public void Relation(int relationConfigObjectId) + { + RelationConfigObjectId = relationConfigObjectId; + FromRelation = true; + } + + public void UnRelation() + { + RelationConfigObjectId = 0; + } +} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectBase.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectBase.cs similarity index 92% rename from src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectBase.cs rename to Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectBase.cs index 574077e5..6d3197d8 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectBase.cs +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectBase.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates; +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; public abstract class ConfigObjectBase : FullAggregateRoot { diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectRelease.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectRelease.cs new file mode 100644 index 00000000..8bd695f5 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/ConfigObjectRelease.cs @@ -0,0 +1,57 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("ConfigObjectReleases")] +public class ConfigObjectRelease : FullAggregateRoot +{ + [Comment("Release type")] + public ReleaseType Type { get; set; } + + [Comment("Config object Id")] + [Required(ErrorMessage = "Config object Id is required")] + [Range(minimum: 1, maximum: int.MaxValue, ErrorMessage = "Config object Id is required")] + public int ConfigObjectId { get; set; } + + [Comment("Rollback From Release Id")] + public int FromReleaseId { get; set; } + + [Comment("If it is rolled back, it will be true")] + public bool IsInvalid { get; set; } + + [Comment("Version format is yyyyMMddHHmmss")] + [Required(ErrorMessage = "Version is required")] + public string Version { get; set; } + + [Comment("Name")] + [Required(ErrorMessage = "Name is required", AllowEmptyStrings = true)] + [StringLength(100, MinimumLength = 2, ErrorMessage = "Name length range is [2-100]")] + public string Name { get; set; } + + [Comment("Comment")] + [Required(ErrorMessage = "Comment is required", AllowEmptyStrings = true)] + [StringLength(500, MinimumLength = 0, ErrorMessage = "Comment length range is [0-500]")] + public string Comment { get; set; } + + [Comment("Content")] + [Required(ErrorMessage = "Content is required", AllowEmptyStrings = true)] + [StringLength(int.MaxValue, MinimumLength = 1, ErrorMessage = "Content length range is [1-2147483647]")] + public string Content { get; set; } + + public ConfigObjectRelease(int configObjectId, string name, string comment, string content, string? version = null, int fromReleaseId = 0, ReleaseType type = ReleaseType.MainRelease) + { + ConfigObjectId = configObjectId; + Name = name; + Comment = comment; + Content = content; + Version = version ?? DateTime.UtcNow.ToString("yyyyMMddHHmmss"); + FromReleaseId = fromReleaseId; + Type = type; + } + + public void Invalid() + { + IsInvalid = true; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfig.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfig.cs new file mode 100644 index 00000000..48e44c17 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfig.cs @@ -0,0 +1,33 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("PublicConfigs")] +public class PublicConfig : FullAggregateRoot +{ + [Required] + public string Name { get; private set; } + + [Required] + public string Identity { get; private set; } + + [Required] + public string Description { get; private set; } + + private readonly List _publicConfigObjects = new(); + public IReadOnlyCollection PublicConfigObjects => _publicConfigObjects; + + public PublicConfig(string name, string identity, string description = "") + { + Name = name; + Identity = identity; + Description = description; + } + + public void Update(string name, string description) + { + Name = name; + Description = description; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfigObject.cs b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfigObject.cs new file mode 100644 index 00000000..151d7201 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/App/Aggregates/PublicConfigObject.cs @@ -0,0 +1,20 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.App.Aggregates; + +[Table("PublicConfigObjects")] +public class PublicConfigObject : ConfigObjectBase +{ + [Required] + [Range(1, int.MaxValue)] + public int PublicConfigId { get; private set; } + + public PublicConfig PublicConfig { get; private set; } = null!; + + public PublicConfigObject(int publicConfigId, int environmentClusterId) + { + PublicConfigId = publicConfigId; + EnvironmentClusterId = environmentClusterId; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/Label/Aggregates/Label.cs b/Masa.Dcc.Infrastructure.Domain/Label/Aggregates/Label.cs new file mode 100644 index 00000000..cd193e03 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/Label/Aggregates/Label.cs @@ -0,0 +1,54 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Domain.Label.Aggregates; + +[Table("Labels")] +[Index(nameof(TypeCode), nameof(IsDeleted), Name = "IX_TypeCode")] +public class Label : FullAggregateRoot +{ + [Comment("Code")] + [Required(ErrorMessage = "Label code is required")] + [StringLength(100, MinimumLength = 2, ErrorMessage = "Label code length range is [2-100]")] + public string Code { get; set; } + + [Comment("Name")] + [Required(ErrorMessage = "Label name is required")] + [StringLength(100, MinimumLength = 2, ErrorMessage = "Label name length range is [2-100]")] + public string Name { get; private set; } + + [Comment("TypeCode")] + [Required(ErrorMessage = "TypeCode is required")] + [StringLength(255, MinimumLength = 0, ErrorMessage = "TypeCode length range is [0-255]")] + public string TypeCode { get; private set; } + + [Comment("TypeName")] + [Required(ErrorMessage = "TypeName is required")] + [StringLength(255, MinimumLength = 0, ErrorMessage = "TypeName length range is [0-255]")] + public string TypeName { get; private set; } + + [Comment("Description")] + [Required(ErrorMessage = "Description is required")] + [StringLength(255, MinimumLength = 0, ErrorMessage = "Description length range is [0-255]")] + public string Description { get; private set; } + + public Label(string code, string name, string typeCode, string typeName, string description = "") + { + Code = code; + Name = name; + TypeCode = typeCode; + TypeName = typeName; + Description = description; + } + + public Label(string code, string name, string typeCode, string typeName, Guid creator, DateTime creationTime, string description = "") + { + Code = code; + Name = name; + TypeCode = typeCode; + TypeName = typeName; + Creator = creator; + CreationTime = creationTime; + Description = description; + } +} diff --git a/Masa.Dcc.Infrastructure.Domain/Masa.Dcc.Infrastructure.Domain.csproj b/Masa.Dcc.Infrastructure.Domain/Masa.Dcc.Infrastructure.Domain.csproj new file mode 100644 index 00000000..6b9c61de --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/Masa.Dcc.Infrastructure.Domain.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Masa.Dcc.Infrastructure.Domain/_Imports.cs b/Masa.Dcc.Infrastructure.Domain/_Imports.cs new file mode 100644 index 00000000..b645f07d --- /dev/null +++ b/Masa.Dcc.Infrastructure.Domain/_Imports.cs @@ -0,0 +1,10 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +global using System.ComponentModel.DataAnnotations; +global using System.ComponentModel.DataAnnotations.Schema; +global using Masa.BuildingBlocks.Ddd.Domain.Entities.Full; +global using Masa.BuildingBlocks.StackSdks.Pm.Enum; +global using Masa.BuildingBlocks.StackSdks.Pm.Model; +global using Masa.Dcc.Contracts.Admin.App.Enums; +global using Microsoft.EntityFrameworkCore; diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/DccDbPostGreSqlContextFactory.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/DccDbPostGreSqlContextFactory.cs new file mode 100644 index 00000000..74025c28 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/DccDbPostGreSqlContextFactory.cs @@ -0,0 +1,20 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Service.Admin.Infrastructure; + +internal class DccDbPostGreSqlContextFactory : IDesignTimeDbContextFactory +{ + public DccDbContext CreateDbContext(string[] args) + { + DccDbContext.RegistAssembly(typeof(DccDbPostGreSqlContextFactory).Assembly); + var optionsBuilder = new MasaDbContextOptionsBuilder(); + var configurationBuilder = new ConfigurationBuilder(); + var configuration = configurationBuilder + .AddJsonFile("appsettings.json") + .Build(); + optionsBuilder.DbContextOptionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Masa.Dcc.Infrastructure.EFCore.PostgreSql")); + + return new DccDbContext(optionsBuilder.MasaOptions); + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs new file mode 100644 index 00000000..e9c3271d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class AppConfigEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs new file mode 100644 index 00000000..ef823e25 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class AppPinEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs new file mode 100644 index 00000000..6b23c5fd --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class AppSecretEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs new file mode 100644 index 00000000..72466d91 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs @@ -0,0 +1,13 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class ConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.Property(m => m.Content).HasColumnType("text"); + builder.Property(m => m.TempContent).HasColumnType("text"); + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs new file mode 100644 index 00000000..f610c14c --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs @@ -0,0 +1,16 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class ConfigObjectReleaseEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.Property(m => m.Type).HasColumnType("smallint"); + builder.Property(m => m.Version).HasColumnType("varchar(20)"); + builder.Property(m => m.Name).HasColumnType("varchar(200)"); + builder.Property(m => m.Comment).HasColumnType("varchar(1000)"); + builder.Property(m => m.Content).HasColumnType("text"); + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs new file mode 100644 index 00000000..26661dee --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class PublicConfigEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs new file mode 100644 index 00000000..ec26dc5d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.App; + +internal class PublicConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs new file mode 100644 index 00000000..e5493e91 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.EntityConfigurations.Label; + +internal class LabelEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Extensition.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Extensition.cs new file mode 100644 index 00000000..e9ecbf3c --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Extensition.cs @@ -0,0 +1,71 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Microsoft.Extensions.DependencyInjection; + +public static class DccPgsqlExtensition +{ + public static MasaDbContextBuilder UsePgsql( + this MasaDbContextBuilder builder, + Action? sqlServerOptionsAction = null) + { + var name = ConnectionStringNameAttribute.GetConnStringName(builder.DbContextType); + builder.Builder = (serviceProvider, dbContextOptionsBuilder) => + { + var connectionStringProvider = serviceProvider.GetRequiredService(); + dbContextOptionsBuilder.UseNpgsql( + connectionStringProvider.GetConnectionString(name), + sqlServerOptionsAction); + }; + return builder; + } + + public static MasaDbContextBuilder UsePgsql( + this MasaDbContextBuilder builder, + string connectionString, + Action? sqlServerOptionsAction = null) + => builder.UsePgCore(connectionString, sqlServerOptionsAction); + + public static MasaDbContextBuilder UsePgsql( + this MasaDbContextBuilder builder, + DbConnection connection, + Action? sqlServerOptionsAction = null) + => builder.UsePgCore(connection, sqlServerOptionsAction); + + private static MasaDbContextBuilder UsePgCore( + this MasaDbContextBuilder builder, + string connectionString, + Action? sqlServerOptionsAction) + { + builder.Builder = (_, dbContextOptionsBuilder) + => dbContextOptionsBuilder.UseNpgsql(connectionString, sqlServerOptionsAction); + return builder.ConfigMasaDbContextAndConnectionStringRelations(connectionString); + } + + private static MasaDbContextBuilder UsePgCore( + this MasaDbContextBuilder builder, + DbConnection connection, + Action? sqlServerOptionsAction = null) + { + builder.Builder = (_, dbContextOptionsBuilder) => dbContextOptionsBuilder.UseNpgsql(connection, sqlServerOptionsAction); + return builder.ConfigMasaDbContextAndConnectionStringRelations(connection.ConnectionString); + } + + internal static MasaDbContextBuilder ConfigMasaDbContextAndConnectionStringRelations( + this MasaDbContextBuilder builder, + string connectionString) + { + var name = ConnectionStringNameAttribute.GetConnStringName(builder.DbContextType); + + builder.Services.Configure(connectionStrings => + { + if (connectionStrings.ContainsKey(name) && + connectionString != connectionStrings.GetConnectionString(name)) + throw new ArgumentException($"The [{builder.DbContextType.Name}] Database Connection String already exists"); + + connectionStrings.TryAdd(name, connectionString); + }); + + return builder; + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Masa.Dcc.Infrastructure.EFCore.PostgreSql.csproj b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Masa.Dcc.Infrastructure.EFCore.PostgreSql.csproj new file mode 100644 index 00000000..dacbdb2d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Masa.Dcc.Infrastructure.EFCore.PostgreSql.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + PreserveNewest + + + + diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.Designer.cs new file mode 100644 index 00000000..df66529f --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.Designer.cs @@ -0,0 +1,583 @@ +// +using System; +using Masa.Dcc.Infrastructure.EFCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.Migrations +{ + [DbContext(typeof(DccDbContext))] + [Migration("20241206040332_dcc-init")] + partial class dccinit + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.29") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer") + .HasComment("AppId"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.ToTable("AppConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppPin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("AppPin"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppSecret", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EncryptionSecret") + .HasColumnType("uuid"); + + b.Property("EnvironmentId") + .HasColumnType("integer"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Secret") + .HasColumnType("uuid"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("AppSecrets"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Identity") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("BizConfigs"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BizConfigId") + .HasColumnType("integer"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("BizConfigId"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.ToTable("BizConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Encryption") + .HasColumnType("boolean"); + + b.Property("FormatLabelCode") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Format"); + + b.Property("FromRelation") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Name"); + + b.Property("RelationConfigObjectId") + .HasColumnType("integer") + .HasComment("Relation config object Id"); + + b.Property("TempContent") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer") + .HasComment("Type"); + + b.HasKey("Id"); + + b.ToTable("ConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObjectRelease", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(1000)") + .HasComment("Comment"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("Config object Id"); + + b.Property("Content") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("text") + .HasComment("Content"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("FromReleaseId") + .HasColumnType("integer") + .HasComment("Rollback From Release Id"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsInvalid") + .HasColumnType("boolean") + .HasComment("If it is rolled back, it will be true"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(200)") + .HasComment("Name"); + + b.Property("Type") + .HasColumnType("smallint") + .HasComment("Release type"); + + b.Property("Version") + .IsRequired() + .HasColumnType("varchar(20)") + .HasComment("Version format is yyyyMMddHHmmss"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId"); + + b.ToTable("ConfigObjectReleases"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Identity") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PublicConfigs"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("PublicConfigId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.HasIndex("PublicConfigId"); + + b.ToTable("PublicConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.Label.Aggregates.Label", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Code"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("Description"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Name"); + + b.Property("TypeCode") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("TypeCode"); + + b.Property("TypeName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("TypeName"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "TypeCode", "IsDeleted" }, "IX_TypeCode"); + + b.ToTable("Labels"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("AppConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ConfigObject"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", "BizConfig") + .WithMany("BizConfigObjects") + .HasForeignKey("BizConfigId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("BizConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BizConfig"); + + b.Navigation("ConfigObject"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObjectRelease", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", null) + .WithMany("ConfigObjectRelease") + .HasForeignKey("ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("PublicConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", "PublicConfig") + .WithMany("PublicConfigObjects") + .HasForeignKey("PublicConfigId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ConfigObject"); + + b.Navigation("PublicConfig"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", b => + { + b.Navigation("BizConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", b => + { + b.Navigation("AppConfigObject") + .IsRequired(); + + b.Navigation("BizConfigObject") + .IsRequired(); + + b.Navigation("ConfigObjectRelease"); + + b.Navigation("PublicConfigObject") + .IsRequired(); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", b => + { + b.Navigation("PublicConfigObjects"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.cs new file mode 100644 index 00000000..5bb0b2cd --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/20241206040332_dcc-init.cs @@ -0,0 +1,332 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.Migrations +{ + public partial class dccinit : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AppPin", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AppId = table.Column(type: "integer", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AppPin", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AppSecrets", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AppId = table.Column(type: "integer", nullable: false), + EnvironmentId = table.Column(type: "integer", nullable: false), + Type = table.Column(type: "integer", nullable: false), + EncryptionSecret = table.Column(type: "uuid", nullable: false), + Secret = table.Column(type: "uuid", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AppSecrets", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "BizConfigs", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Identity = table.Column(type: "text", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BizConfigs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ConfigObjects", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, comment: "Name"), + FormatLabelCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, comment: "Format"), + Type = table.Column(type: "integer", nullable: false, comment: "Type"), + Encryption = table.Column(type: "boolean", nullable: false), + Content = table.Column(type: "text", nullable: false), + TempContent = table.Column(type: "text", nullable: false), + RelationConfigObjectId = table.Column(type: "integer", nullable: false, comment: "Relation config object Id"), + FromRelation = table.Column(type: "boolean", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConfigObjects", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Labels", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Code = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, comment: "Code"), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, comment: "Name"), + TypeCode = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "TypeCode"), + TypeName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "TypeName"), + Description = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Description"), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Labels", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PublicConfigs", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Identity = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PublicConfigs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AppConfigObjects", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AppId = table.Column(type: "integer", nullable: false, comment: "AppId"), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + ConfigObjectId = table.Column(type: "integer", nullable: false, comment: "ConfigObjectId"), + EnvironmentClusterId = table.Column(type: "integer", nullable: false, comment: "EnvironmentClusterId") + }, + constraints: table => + { + table.PrimaryKey("PK_AppConfigObjects", x => x.Id); + table.ForeignKey( + name: "FK_AppConfigObjects_ConfigObjects_ConfigObjectId", + column: x => x.ConfigObjectId, + principalTable: "ConfigObjects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "BizConfigObjects", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + BizConfigId = table.Column(type: "integer", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + ConfigObjectId = table.Column(type: "integer", nullable: false, comment: "ConfigObjectId"), + EnvironmentClusterId = table.Column(type: "integer", nullable: false, comment: "EnvironmentClusterId") + }, + constraints: table => + { + table.PrimaryKey("PK_BizConfigObjects", x => x.Id); + table.ForeignKey( + name: "FK_BizConfigObjects_BizConfigs_BizConfigId", + column: x => x.BizConfigId, + principalTable: "BizConfigs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_BizConfigObjects_ConfigObjects_ConfigObjectId", + column: x => x.ConfigObjectId, + principalTable: "ConfigObjects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ConfigObjectReleases", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Type = table.Column(type: "smallint", nullable: false, comment: "Release type"), + ConfigObjectId = table.Column(type: "integer", nullable: false, comment: "Config object Id"), + FromReleaseId = table.Column(type: "integer", nullable: false, comment: "Rollback From Release Id"), + IsInvalid = table.Column(type: "boolean", nullable: false, comment: "If it is rolled back, it will be true"), + Version = table.Column(type: "varchar(20)", nullable: false, comment: "Version format is yyyyMMddHHmmss"), + Name = table.Column(type: "varchar(200)", maxLength: 100, nullable: false, comment: "Name"), + Comment = table.Column(type: "varchar(1000)", maxLength: 500, nullable: false, comment: "Comment"), + Content = table.Column(type: "text", maxLength: 2147483647, nullable: false, comment: "Content"), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConfigObjectReleases", x => x.Id); + table.ForeignKey( + name: "FK_ConfigObjectReleases_ConfigObjects_ConfigObjectId", + column: x => x.ConfigObjectId, + principalTable: "ConfigObjects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PublicConfigObjects", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PublicConfigId = table.Column(type: "integer", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + ConfigObjectId = table.Column(type: "integer", nullable: false, comment: "ConfigObjectId"), + EnvironmentClusterId = table.Column(type: "integer", nullable: false, comment: "EnvironmentClusterId") + }, + constraints: table => + { + table.PrimaryKey("PK_PublicConfigObjects", x => x.Id); + table.ForeignKey( + name: "FK_PublicConfigObjects_ConfigObjects_ConfigObjectId", + column: x => x.ConfigObjectId, + principalTable: "ConfigObjects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PublicConfigObjects_PublicConfigs_PublicConfigId", + column: x => x.PublicConfigId, + principalTable: "PublicConfigs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AppConfigObjects_ConfigObjectId", + table: "AppConfigObjects", + column: "ConfigObjectId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_BizConfigObjects_BizConfigId", + table: "BizConfigObjects", + column: "BizConfigId"); + + migrationBuilder.CreateIndex( + name: "IX_BizConfigObjects_ConfigObjectId", + table: "BizConfigObjects", + column: "ConfigObjectId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ConfigObjectReleases_ConfigObjectId", + table: "ConfigObjectReleases", + column: "ConfigObjectId"); + + migrationBuilder.CreateIndex( + name: "IX_TypeCode", + table: "Labels", + columns: new[] { "TypeCode", "IsDeleted" }); + + migrationBuilder.CreateIndex( + name: "IX_PublicConfigObjects_ConfigObjectId", + table: "PublicConfigObjects", + column: "ConfigObjectId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_PublicConfigObjects_PublicConfigId", + table: "PublicConfigObjects", + column: "PublicConfigId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AppConfigObjects"); + + migrationBuilder.DropTable( + name: "AppPin"); + + migrationBuilder.DropTable( + name: "AppSecrets"); + + migrationBuilder.DropTable( + name: "BizConfigObjects"); + + migrationBuilder.DropTable( + name: "ConfigObjectReleases"); + + migrationBuilder.DropTable( + name: "Labels"); + + migrationBuilder.DropTable( + name: "PublicConfigObjects"); + + migrationBuilder.DropTable( + name: "BizConfigs"); + + migrationBuilder.DropTable( + name: "ConfigObjects"); + + migrationBuilder.DropTable( + name: "PublicConfigs"); + } + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/DccDbContextModelSnapshot.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/DccDbContextModelSnapshot.cs new file mode 100644 index 00000000..349c27aa --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/Migrations/DccDbContextModelSnapshot.cs @@ -0,0 +1,581 @@ +// +using System; +using Masa.Dcc.Infrastructure.EFCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Masa.Dcc.Infrastructure.EFCore.PostgreSql.Migrations +{ + [DbContext(typeof(DccDbContext))] + partial class DccDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.29") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer") + .HasComment("AppId"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.ToTable("AppConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppPin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("AppPin"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppSecret", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppId") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EncryptionSecret") + .HasColumnType("uuid"); + + b.Property("EnvironmentId") + .HasColumnType("integer"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Secret") + .HasColumnType("uuid"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("AppSecrets"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Identity") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("BizConfigs"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BizConfigId") + .HasColumnType("integer"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("BizConfigId"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.ToTable("BizConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Encryption") + .HasColumnType("boolean"); + + b.Property("FormatLabelCode") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Format"); + + b.Property("FromRelation") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Name"); + + b.Property("RelationConfigObjectId") + .HasColumnType("integer") + .HasComment("Relation config object Id"); + + b.Property("TempContent") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer") + .HasComment("Type"); + + b.HasKey("Id"); + + b.ToTable("ConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObjectRelease", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(1000)") + .HasComment("Comment"); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("Config object Id"); + + b.Property("Content") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("text") + .HasComment("Content"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("FromReleaseId") + .HasColumnType("integer") + .HasComment("Rollback From Release Id"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsInvalid") + .HasColumnType("boolean") + .HasComment("If it is rolled back, it will be true"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(200)") + .HasComment("Name"); + + b.Property("Type") + .HasColumnType("smallint") + .HasComment("Release type"); + + b.Property("Version") + .IsRequired() + .HasColumnType("varchar(20)") + .HasComment("Version format is yyyyMMddHHmmss"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId"); + + b.ToTable("ConfigObjectReleases"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Identity") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PublicConfigs"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigObjectId") + .HasColumnType("integer") + .HasComment("ConfigObjectId"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("EnvironmentClusterId") + .HasColumnType("integer") + .HasComment("EnvironmentClusterId"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("PublicConfigId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ConfigObjectId") + .IsUnique(); + + b.HasIndex("PublicConfigId"); + + b.ToTable("PublicConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.Label.Aggregates.Label", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Code"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("Description"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasComment("Name"); + + b.Property("TypeCode") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("TypeCode"); + + b.Property("TypeName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasComment("TypeName"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "TypeCode", "IsDeleted" }, "IX_TypeCode"); + + b.ToTable("Labels"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("AppConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.AppConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ConfigObject"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", "BizConfig") + .WithMany("BizConfigObjects") + .HasForeignKey("BizConfigId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("BizConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BizConfig"); + + b.Navigation("ConfigObject"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObjectRelease", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", null) + .WithMany("ConfigObjectRelease") + .HasForeignKey("ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", b => + { + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", "ConfigObject") + .WithOne("PublicConfigObject") + .HasForeignKey("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfigObject", "ConfigObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", "PublicConfig") + .WithMany("PublicConfigObjects") + .HasForeignKey("PublicConfigId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ConfigObject"); + + b.Navigation("PublicConfig"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.BizConfig", b => + { + b.Navigation("BizConfigObjects"); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.ConfigObject", b => + { + b.Navigation("AppConfigObject") + .IsRequired(); + + b.Navigation("BizConfigObject") + .IsRequired(); + + b.Navigation("ConfigObjectRelease"); + + b.Navigation("PublicConfigObject") + .IsRequired(); + }); + + modelBuilder.Entity("Masa.Dcc.Infrastructure.Domain.App.Aggregates.PublicConfig", b => + { + b.Navigation("PublicConfigObjects"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/_Imports.cs b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/_Imports.cs new file mode 100644 index 00000000..5c1eff06 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/_Imports.cs @@ -0,0 +1,12 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +global using Masa.Dcc.Infrastructure.Domain.App.Aggregates; +global using Microsoft.EntityFrameworkCore; +global using Microsoft.EntityFrameworkCore.Metadata.Builders; +global using Masa.Dcc.Infrastructure.EFCore; +global using Microsoft.EntityFrameworkCore.Design; +global using Microsoft.Extensions.Configuration; +global using System.Data.Common; +global using Masa.BuildingBlocks.Data; +global using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; diff --git a/Masa.Dcc.Infrastructure.EFCore.PostgreSql/appsettings.json b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/appsettings.json new file mode 100644 index 00000000..c153468d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.PostgreSql/appsettings.json @@ -0,0 +1,6 @@ +{ + "ConnectionStrings": { + //only migration open + "DefaultConnection": "Host=10.130.0.19;Port=3815;Database=dcc_dev1;Username=ss;Password=Lsd@2023" + } +} \ No newline at end of file diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/DccDbContextFactory.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/DccDbSqlServerContextFactory.cs similarity index 59% rename from src/Services/Masa.Dcc.Service/Infrastructure/DccDbContextFactory.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/DccDbSqlServerContextFactory.cs index 27dd207f..480db385 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/DccDbContextFactory.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/DccDbSqlServerContextFactory.cs @@ -1,18 +1,19 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Infrastructure; +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer; -public class DccDbContextFactory : IDesignTimeDbContextFactory +internal class DccDbSqlServerContextFactory : IDesignTimeDbContextFactory { public DccDbContext CreateDbContext(string[] args) { + DccDbContext.RegistAssembly(typeof(DccDbSqlServerContextFactory).Assembly); var optionsBuilder = new MasaDbContextOptionsBuilder(); var configurationBuilder = new ConfigurationBuilder(); var configuration = configurationBuilder - .AddJsonFile("appsettings.Development.json") + .AddJsonFile("appsettings.json") .Build(); - optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection")); + optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"), mbox => mbox.MigrationsAssembly("Masa.Dcc.Infrastructure.EFCore.SqlServer")); return new DccDbContext(optionsBuilder.MasaOptions); } diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs new file mode 100644 index 00000000..b712b7f9 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class AppConfigEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs new file mode 100644 index 00000000..cc733325 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class AppPinEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs new file mode 100644 index 00000000..b965106d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class AppSecretEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs new file mode 100644 index 00000000..78ef7782 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs @@ -0,0 +1,13 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class ConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.Property(m => m.Content).HasColumnType("ntext"); + builder.Property(m => m.TempContent).HasColumnType("ntext"); + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs new file mode 100644 index 00000000..b0af96f6 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs @@ -0,0 +1,16 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class ConfigObjectReleaseEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.Property(m => m.Type).HasColumnType("tinyint"); + builder.Property(m => m.Version).HasColumnType("varchar(20)"); + builder.Property(m => m.Name).HasColumnType("nvarchar(100)"); + builder.Property(m => m.Comment).HasColumnType("nvarchar(500)"); + builder.Property(m => m.Content).HasColumnType("ntext"); + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs new file mode 100644 index 00000000..50c524be --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class PublicConfigEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs new file mode 100644 index 00000000..f9b54fa7 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.App; + +internal class PublicConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs new file mode 100644 index 00000000..26c16c76 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.EFCore.SqlServer.EntityConfigurations.Label; + +internal class LabelEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + } +} diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/Masa.Dcc.Infrastructure.EFCore.SqlServer.csproj b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Masa.Dcc.Infrastructure.EFCore.SqlServer.csproj new file mode 100644 index 00000000..ed93f694 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Masa.Dcc.Infrastructure.EFCore.SqlServer.csproj @@ -0,0 +1,29 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + PreserveNewest + + + + diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220425085849_InitCreate.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220425085849_InitCreate.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220425085849_InitCreate.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220425085849_InitCreate.Designer.cs index 61d3226d..a0b25b18 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220425085849_InitCreate.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220425085849_InitCreate.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220425085849_InitCreate.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220425085849_InitCreate.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220425085849_InitCreate.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220425085849_InitCreate.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427062448_UpdateConfigObject.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427062448_UpdateConfigObject.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220427062448_UpdateConfigObject.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427062448_UpdateConfigObject.Designer.cs index 7036630d..fb43b705 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220427062448_UpdateConfigObject.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427062448_UpdateConfigObject.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427062448_UpdateConfigObject.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427062448_UpdateConfigObject.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220427062448_UpdateConfigObject.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427062448_UpdateConfigObject.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs index de4d129b..c4508a5e 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427072629_AddConfigObjectRelease.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427072629_AddConfigObjectRelease.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427072629_AddConfigObjectRelease.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220427072629_AddConfigObjectRelease.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427072629_AddConfigObjectRelease.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs index efc023f2..0ddcf34c 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427151055_UpdateConfigObjectType.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220427151055_UpdateConfigObjectType.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427151055_UpdateConfigObjectType.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220427151055_UpdateConfigObjectType.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220427151055_UpdateConfigObjectType.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs index e1a74c0a..94f2fb66 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428095529_UpdateConfigObjectReleaseField.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428095529_UpdateConfigObjectReleaseField.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428095529_UpdateConfigObjectReleaseField.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220428095529_UpdateConfigObjectReleaseField.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428095529_UpdateConfigObjectReleaseField.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs index ffcc73cb..bc22cb1e 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428145639_AddConfigObjectReleaseField.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428145639_AddConfigObjectReleaseField.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428145639_AddConfigObjectReleaseField.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220428145639_AddConfigObjectReleaseField.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428145639_AddConfigObjectReleaseField.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs index eed79d17..a1408034 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220428164222_UpdateConfigObjectReleaseRollbackField.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220509084824_AddAppPin.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220509084824_AddAppPin.Designer.cs similarity index 98% rename from src/Services/Masa.Dcc.Service/Migrations/20220509084824_AddAppPin.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220509084824_AddAppPin.Designer.cs index 63896a24..bdef772b 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220509084824_AddAppPin.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220509084824_AddAppPin.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220509084824_AddAppPin.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220509084824_AddAppPin.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220509084824_AddAppPin.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220509084824_AddAppPin.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220511100747_AddBizConfig.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220511100747_AddBizConfig.Designer.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/20220511100747_AddBizConfig.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220511100747_AddBizConfig.Designer.cs index ac2a4adc..dfc03ca7 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220511100747_AddBizConfig.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220511100747_AddBizConfig.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220511100747_AddBizConfig.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220511100747_AddBizConfig.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220511100747_AddBizConfig.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220511100747_AddBizConfig.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220515093911_AddLabelCode.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220515093911_AddLabelCode.Designer.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/20220515093911_AddLabelCode.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220515093911_AddLabelCode.Designer.cs index 0a43eb3f..fd14d009 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220515093911_AddLabelCode.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220515093911_AddLabelCode.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220515093911_AddLabelCode.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220515093911_AddLabelCode.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220515093911_AddLabelCode.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220515093911_AddLabelCode.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220609095708_AddFromRelation.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220609095708_AddFromRelation.Designer.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/20220609095708_AddFromRelation.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220609095708_AddFromRelation.Designer.cs index 4d1c5adb..85150b8a 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20220609095708_AddFromRelation.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220609095708_AddFromRelation.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20220609095708_AddFromRelation.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220609095708_AddFromRelation.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20220609095708_AddFromRelation.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20220609095708_AddFromRelation.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20221114064033_AddEncryption.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20221114064033_AddEncryption.Designer.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/20221114064033_AddEncryption.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20221114064033_AddEncryption.Designer.cs index 9b1c7adb..3d9d515a 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20221114064033_AddEncryption.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20221114064033_AddEncryption.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20221114064033_AddEncryption.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20221114064033_AddEncryption.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20221114064033_AddEncryption.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20221114064033_AddEncryption.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/20230518035332_ExpandContent.Designer.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20230518035332_ExpandContent.Designer.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/20230518035332_ExpandContent.Designer.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20230518035332_ExpandContent.Designer.cs index 665217ed..9eebe75d 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/20230518035332_ExpandContent.Designer.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20230518035332_ExpandContent.Designer.cs @@ -1,11 +1,7 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/src/Services/Masa.Dcc.Service/Migrations/20230518035332_ExpandContent.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20230518035332_ExpandContent.cs similarity index 100% rename from src/Services/Masa.Dcc.Service/Migrations/20230518035332_ExpandContent.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/20230518035332_ExpandContent.cs diff --git a/src/Services/Masa.Dcc.Service/Migrations/DccDbContextModelSnapshot.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/DccDbContextModelSnapshot.cs similarity index 99% rename from src/Services/Masa.Dcc.Service/Migrations/DccDbContextModelSnapshot.cs rename to Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/DccDbContextModelSnapshot.cs index 1d658945..9e6de458 100644 --- a/src/Services/Masa.Dcc.Service/Migrations/DccDbContextModelSnapshot.cs +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/Migrations/DccDbContextModelSnapshot.cs @@ -1,10 +1,6 @@ // -using System; -using Masa.Dcc.Service.Infrastructure; -using Microsoft.EntityFrameworkCore; +using Masa.Dcc.Infrastructure.EFCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/_Imports.cs b/Masa.Dcc.Infrastructure.EFCore.SqlServer/_Imports.cs new file mode 100644 index 00000000..c189cffe --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/_Imports.cs @@ -0,0 +1,8 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +global using Masa.Dcc.Infrastructure.Domain.App.Aggregates; +global using Microsoft.EntityFrameworkCore; +global using Microsoft.EntityFrameworkCore.Metadata.Builders; +global using Microsoft.EntityFrameworkCore.Design; +global using Microsoft.Extensions.Configuration; diff --git a/Masa.Dcc.Infrastructure.EFCore.SqlServer/appsettings.json b/Masa.Dcc.Infrastructure.EFCore.SqlServer/appsettings.json new file mode 100644 index 00000000..9942c93e --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore.SqlServer/appsettings.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=10.130.0.19:2415;Database=dcc_dev;User Id=ss;Password=Hzss@123;" + } +} \ No newline at end of file diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/DccDbContext.cs b/Masa.Dcc.Infrastructure.EFCore/DccDbContext.cs similarity index 64% rename from src/Services/Masa.Dcc.Service/Infrastructure/DccDbContext.cs rename to Masa.Dcc.Infrastructure.EFCore/DccDbContext.cs index 2d777f7c..050a69c6 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/DccDbContext.cs +++ b/Masa.Dcc.Infrastructure.EFCore/DccDbContext.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Infrastructure; +namespace Masa.Dcc.Infrastructure.EFCore; public class DccDbContext : MasaDbContext { @@ -10,10 +10,16 @@ public DccDbContext(MasaDbContextOptions options) : base(options) ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; } + public static Assembly Assembly { get; private set; } = typeof(DccDbContext).Assembly; + + public static void RegistAssembly(Assembly assembly) + { + Assembly = assembly; + } + protected override void OnModelCreatingExecuting(ModelBuilder builder) { - builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - builder.ApplyConfiguration(new IntegrationEventLogEntityTypeConfiguration()); + builder.ApplyConfigurationsFromAssembly(Assembly); base.OnModelCreatingExecuting(builder); } } diff --git a/Masa.Dcc.Infrastructure.EFCore/Masa.Dcc.Infrastructure.EFCore.csproj b/Masa.Dcc.Infrastructure.EFCore/Masa.Dcc.Infrastructure.EFCore.csproj new file mode 100644 index 00000000..fe34697d --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore/Masa.Dcc.Infrastructure.EFCore.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Masa.Dcc.Infrastructure.EFCore/_Imports.cs b/Masa.Dcc.Infrastructure.EFCore/_Imports.cs new file mode 100644 index 00000000..df4881b7 --- /dev/null +++ b/Masa.Dcc.Infrastructure.EFCore/_Imports.cs @@ -0,0 +1,5 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +global using System.Reflection; +global using Microsoft.EntityFrameworkCore; diff --git a/Masa.Dcc.Infrastructure.Repository/App/IAppConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IAppConfigObjectRepository.cs new file mode 100644 index 00000000..ca217c55 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/App/IAppConfigObjectRepository.cs @@ -0,0 +1,16 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IAppConfigObjectRepository : IRepository +{ + Task> GetListByAppIdAsync(int appId); + + Task> GetListByEnvClusterIdAsync(int envClusterId, int appId, bool getLatestRelease = false); + + Task> GetAppLatestReleaseConfigAsync(IEnumerable appIds, + int? envClusterId = null); + + Task GetbyConfigObjectIdAsync(int configObjectId); +} diff --git a/Masa.Dcc.Infrastructure.Repository/App/IAppPinRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IAppPinRepository.cs new file mode 100644 index 00000000..265544b7 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/App/IAppPinRepository.cs @@ -0,0 +1,9 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IAppPinRepository : IRepository +{ + Task> GetListAsync(List appIds); +} diff --git a/Masa.Dcc.Infrastructure.Repository/App/IBizConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IBizConfigObjectRepository.cs new file mode 100644 index 00000000..daefcc30 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/App/IBizConfigObjectRepository.cs @@ -0,0 +1,17 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IBizConfigObjectRepository : IRepository +{ + Task> GetListByEnvClusterIdAsync(int envClusterId, int bizConfigId, + bool getLatestRelease = false); + + Task> GetListByBizConfigIdAsync(int bizConfigId); + + Task> GetProjectLatestReleaseConfigAsync( + List projects, int? envClusterId = null); + + Task GetByConfigObjectIdAsync(int configObjectId); +} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IBizConfigRepository.cs similarity index 53% rename from src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigRepository.cs rename to Masa.Dcc.Infrastructure.Repository/App/IBizConfigRepository.cs index 254b386b..fa6b522d 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigRepository.cs +++ b/Masa.Dcc.Infrastructure.Repository/App/IBizConfigRepository.cs @@ -1,9 +1,8 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IBizConfigRepository : IRepository { - public interface IBizConfigRepository : IRepository - { - } } diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectReleaseRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IConfigObjectReleaseRepository.cs similarity index 50% rename from src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectReleaseRepository.cs rename to Masa.Dcc.Infrastructure.Repository/App/IConfigObjectReleaseRepository.cs index d7fea75e..14083c82 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectReleaseRepository.cs +++ b/Masa.Dcc.Infrastructure.Repository/App/IConfigObjectReleaseRepository.cs @@ -1,9 +1,8 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IConfigObjectReleaseRepository : IRepository { - public interface IConfigObjectReleaseRepository : IRepository - { - } } diff --git a/Masa.Dcc.Infrastructure.Repository/App/IConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IConfigObjectRepository.cs new file mode 100644 index 00000000..cd523c94 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/App/IConfigObjectRepository.cs @@ -0,0 +1,13 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IConfigObjectRepository : IRepository +{ + Task GetConfigObjectWithReleaseHistoriesAsync(int Id); + + Task> GetRelationConfigObjectWithReleaseHistoriesAsync(int Id); + + Task> GetNewestConfigObjectReleaseWithAppInfo(); +} diff --git a/Masa.Dcc.Infrastructure.Repository/App/IPublicConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IPublicConfigObjectRepository.cs new file mode 100644 index 00000000..3ee93939 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/App/IPublicConfigObjectRepository.cs @@ -0,0 +1,14 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IPublicConfigObjectRepository : IRepository +{ + Task> GetListByEnvClusterIdAsync(int? envClusterId, int publicConfigId, + bool getLatestRelease = false); + + Task GetByConfigObjectIdAsync(int configObjectId); + + Task> GetListByPublicConfigIdAsync(int publicConfigId); +} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigRepository.cs b/Masa.Dcc.Infrastructure.Repository/App/IPublicConfigRepository.cs similarity index 52% rename from src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigRepository.cs rename to Masa.Dcc.Infrastructure.Repository/App/IPublicConfigRepository.cs index 7660d62d..3dd2c930 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigRepository.cs +++ b/Masa.Dcc.Infrastructure.Repository/App/IPublicConfigRepository.cs @@ -1,9 +1,8 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories +namespace Masa.Dcc.Infrastructure.Repository.App; + +public interface IPublicConfigRepository : IRepository { - public interface IPublicConfigRepository : IRepository - { - } } diff --git a/src/Services/Masa.Dcc.Service/Domain/Label/Repositories/ILabelRepository.cs b/Masa.Dcc.Infrastructure.Repository/Label/ILabelRepository.cs similarity index 52% rename from src/Services/Masa.Dcc.Service/Domain/Label/Repositories/ILabelRepository.cs rename to Masa.Dcc.Infrastructure.Repository/Label/ILabelRepository.cs index 9d959f93..e11456d2 100644 --- a/src/Services/Masa.Dcc.Service/Domain/Label/Repositories/ILabelRepository.cs +++ b/Masa.Dcc.Infrastructure.Repository/Label/ILabelRepository.cs @@ -1,9 +1,8 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.Label.Repositories +namespace Masa.Dcc.Infrastructure.Repository.Label; + +public interface ILabelRepository : IRepository { - public interface ILabelRepository : IRepository - { - } } diff --git a/Masa.Dcc.Infrastructure.Repository/Masa.Dcc.Infrastructure.Repository.csproj b/Masa.Dcc.Infrastructure.Repository/Masa.Dcc.Infrastructure.Repository.csproj new file mode 100644 index 00000000..149ce029 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Masa.Dcc.Infrastructure.Repository.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppConfigObjectRepository.cs new file mode 100644 index 00000000..84c2a0a7 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppConfigObjectRepository.cs @@ -0,0 +1,76 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class AppConfigObjectRepository : Repository, IAppConfigObjectRepository +{ + public AppConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } + + public async Task> GetListByEnvClusterIdAsync(int envClusterId, int appId, + bool getLatestRelease) + { + var configData = await Context.Set() + .Where(appConfigObject => appConfigObject.EnvironmentClusterId == envClusterId && appConfigObject.AppId == appId) + .Include(appConfigObject => appConfigObject.ConfigObject) + .AsNoTracking().ToListAsync(); + + if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); + + return configData; + } + + public async Task> GetAppLatestReleaseConfigAsync(IEnumerable appIds, int? envClusterId) + { + List<(int AppId, ConfigObjectRelease Release)> result = new(); + if (appIds?.Any() != true) + { + return result; + } + Expression> condition = appConfig => appIds.Contains(appConfig.AppId); + if (envClusterId.HasValue) + { + condition.And(x => x.EnvironmentClusterId == envClusterId.Value); + } + var qConfigs = Context.Set() + .Where(condition) + .Select(b => new { b.ConfigObjectId, b.AppId }); + + var qRelease = from biz in qConfigs + join r in Context.Set() on biz.ConfigObjectId equals r.ConfigObjectId into rNullable + from release in rNullable.DefaultIfEmpty() + select new { biz.AppId, release }; + + var qResult = await qRelease.OrderByDescending(x => x.release.CreationTime).AsNoTracking().ToListAsync(); + foreach (var appId in appIds) + { + var app = qResult.FirstOrDefault(x => x.AppId == appId); + if (app != null && app.release != null) + { + result.Add((appId, app.release)); + } + } + return result; + } + + public async Task> GetListByAppIdAsync(int appId) + { + var configData = await Context.Set() + .Include(appConfigObject => appConfigObject.ConfigObject) + .Where(appConfigObject => appConfigObject.AppId == appId) + .ToListAsync(); + + return configData; + } + + + public async Task GetbyConfigObjectIdAsync(int configObjectId) + { + var result = await Context.Set() + .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); + + return result ?? new(0, 0); + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppPinRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppPinRepository.cs new file mode 100644 index 00000000..0d94ad25 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/AppPinRepository.cs @@ -0,0 +1,22 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class AppPinRepository : Repository, IAppPinRepository +{ + public AppPinRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { } + + public async Task> GetListAsync(List appIds) + { + var result = await Context.Set() + .IgnoreQueryFilters() + .Where(app => appIds.Contains(app.AppId)) + .GroupBy(app => app.AppId) + .Select(app => app.OrderByDescending(a => a.Id).First()) + .ToListAsync(); + + return result; + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigObjectRepository.cs new file mode 100644 index 00000000..4f32d4fe --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigObjectRepository.cs @@ -0,0 +1,99 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class BizConfigObjectRepository : Repository, IBizConfigObjectRepository +{ + public BizConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } + + public async Task> GetListByEnvClusterIdAsync(int envClusterId, int bizConfigId, + bool getLatestRelease) + { + var configData = await Context.Set() + .Where(bizConfigObject => bizConfigObject.EnvironmentClusterId == envClusterId && + bizConfigObject.BizConfigId == bizConfigId) + .Include(bizConfigObject => bizConfigObject.ConfigObject) + .ToListAsync(); + + if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); + + return configData; + } + + public async Task> GetListByBizConfigIdAsync(int bizConfigId) + { + var bizConfigObjects = await Context.Set() + .Include(bizConfigObject => bizConfigObject.ConfigObject) + .Where(bizConfigObject => bizConfigObject.BizConfigId == bizConfigId) + .ToListAsync(); + + return bizConfigObjects; + } + + public async Task> + GetProjectLatestReleaseConfigAsync( + List projects, int? envClusterId = null) + { + + List<(ConfigObjectRelease Release, int ProjectId)> result = new(); + if (projects?.Any() != true) + { + return result; + } + + var identities = projects.Select(x => (x.Identity + DccConst.BizConfigSuffix).ToLower()); + //var bizConfigs = await qBizConfigs.ToListAsync(); + + //var qReleases = Context.Set().GroupBy(r => r.ConfigObjectId) + // .Select(x => x.OrderByDescending(x => x.CreationTime).FirstOrDefault()); + ////select new { release = g.OrderByDescending(x => x.CreationTime).FirstOrDefault(), biz.BizConfig } + //; + //var test = await qReleases.ToListAsync(); + //var q = from biz in qBizConfigs + // join r in qReleases on biz.ConfigObjectId equals r.ConfigObjectId into rNullable + // from release in rNullable.DefaultIfEmpty() + // // where identities.Contains(biz.BizConfig.Identity) + // select new { biz.BizConfig.Identity }; + // TODO Group by is not support to join,it support in EFCore 7.0 https://github.com/dotnet/efcore/issues/24106 + + Expression> condition = x => identities.Contains(x.BizConfig.Identity); + if (envClusterId.HasValue) + { + condition.And(x => x.EnvironmentClusterId == envClusterId.Value); + } + var qConfigs = Context.Set() + .Include(x => x.BizConfig) + .Where(condition) + .Select(b => new { b.BizConfig.Identity, b.ConfigObjectId }); + + var qReleases = from biz in qConfigs + join r in Context.Set() on biz.ConfigObjectId equals r.ConfigObjectId into rNullable + from release in rNullable.DefaultIfEmpty() + select new { biz.Identity, release }; + + var qResult = await qReleases.OrderByDescending(x => x.release.CreationTime).AsNoTracking().ToListAsync(); + + foreach (var project in projects) + { + var m = qResult.FirstOrDefault(x => string.Equals(x.Identity, + project.Identity + DccConst.BizConfigSuffix, StringComparison.InvariantCultureIgnoreCase)); + if (m != null && m.release != null) + { + result.Add((m.release, project.Id)); + } + } + + return result; + } + + public async Task GetByConfigObjectIdAsync(int configObjectId) + { + var result = await Context.Set() + .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); + + return result ?? new(0, 0); + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigRepository.cs new file mode 100644 index 00000000..c63af1bf --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/BizConfigRepository.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class BizConfigRepository : Repository, IBizConfigRepository +{ + public BizConfigRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectReleaseRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectReleaseRepository.cs new file mode 100644 index 00000000..e7323d10 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectReleaseRepository.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class ConfigObjectReleaseRepository : Repository, IConfigObjectReleaseRepository +{ + public ConfigObjectReleaseRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectRepository.cs new file mode 100644 index 00000000..7b6f8ad8 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/ConfigObjectRepository.cs @@ -0,0 +1,89 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class ConfigObjectRepository : Repository, IConfigObjectRepository +{ + public ConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } + + public async Task GetConfigObjectWithReleaseHistoriesAsync(int id) + { + var configObject = await Context.Set() + .Where(configObject => configObject.Id == id) + .Include(configObject => configObject.ConfigObjectRelease) + .FirstOrDefaultAsync(); + + return configObject ?? throw new Exception("Config object does not exist"); + } + + public async Task> GetRelationConfigObjectWithReleaseHistoriesAsync(int id) + { + var configObjects = await Context.Set() + .Where(configObject => configObject.RelationConfigObjectId == id) + .Include(configObject => configObject.ConfigObjectRelease) + .ToListAsync(); + + return configObjects; + } + + public async Task> GetNewestConfigObjectReleaseWithAppInfo() + { + var configObjectReleaseQuery = Context.Set() + .Join( + Context.Set(), + configObject => configObject.Id, + configObjectRelease => configObjectRelease.ConfigObjectId, + (configObject, configObjectRelease) => new + { + ConfigObject = configObject, + ConfigObjectReleaseId = configObjectRelease.Id, + } + ); + + var result = await configObjectReleaseQuery + .Join( + Context.Set(), + configObjectGroup => configObjectGroup.ConfigObject.Id, + appConfigObject => appConfigObject.ConfigObjectId, + (configObjectGroup, appConfigObject) => new + { + configObjectGroup.ConfigObject, + configObjectGroup.ConfigObjectReleaseId, + configObjectGroup.ConfigObject.Type, + appConfigObject.AppId, + appConfigObject.EnvironmentClusterId + } + ) + .GroupBy(config => config.ConfigObject.Id) + .Select(config => config.OrderByDescending(c => c.ConfigObjectReleaseId).First()) + .ToListAsync(); + + var publicResult = await configObjectReleaseQuery + .Join( + Context.Set(), + configObjectGroup => configObjectGroup.ConfigObject.Id, + publicConfigObject => publicConfigObject.ConfigObjectId, + (configObjectGroup, publicConfigObject) => new + { + configObjectGroup.ConfigObject, + configObjectGroup.ConfigObjectReleaseId, + configObjectGroup.ConfigObject.Type, + publicConfigObject.PublicConfigId, + publicConfigObject.EnvironmentClusterId + } + ) + .GroupBy(config => config.ConfigObject.Id) + .Select(config => config.OrderByDescending(c => c.ConfigObjectReleaseId).First()) + .ToListAsync(); + + return result + .Select(config => + new ValueTuple(config.ConfigObject, config.AppId, config.EnvironmentClusterId)) + .Union(publicResult.Select(config => + new ValueTuple(config.ConfigObject, config.PublicConfigId, config.EnvironmentClusterId))) + .ToList(); + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigObjectRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigObjectRepository.cs new file mode 100644 index 00000000..db129a35 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigObjectRepository.cs @@ -0,0 +1,46 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class PublicConfigObjectRepository : Repository, IPublicConfigObjectRepository +{ + public PublicConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } + + public async Task> GetListByEnvClusterIdAsync(int? envClusterId, int publicConfigId, + bool getLatestRelease) + { + Expression> condition = p => p.PublicConfigId == publicConfigId; + if (envClusterId.HasValue && envClusterId != 0) + condition = condition.And(p => p.EnvironmentClusterId == envClusterId); + + var configData = await Context.Set() + .Where(condition) + .Include(publicConfigObject => publicConfigObject.ConfigObject) + .ToListAsync(); + + if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); + + return configData; + } + + public async Task GetByConfigObjectIdAsync(int configObjectId) + { + var result = await Context.Set() + .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); + + return result ?? new(0, 0); + } + + public async Task> GetListByPublicConfigIdAsync(int publicConfigId) + { + var configData = await Context.Set() + .Include(pubConfig => pubConfig.ConfigObject) + .Where(pubConfig => pubConfig.PublicConfigId == publicConfigId) + .ToListAsync(); + + return configData; + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigRepository.cs new file mode 100644 index 00000000..373774d7 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/App/PublicConfigRepository.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.App; + +internal class PublicConfigRepository : Repository, IPublicConfigRepository +{ + public PublicConfigRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } +} diff --git a/Masa.Dcc.Infrastructure.Repository/Repositories/Label/LabelRepository.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/Label/LabelRepository.cs new file mode 100644 index 00000000..8df89707 --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/Label/LabelRepository.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Infrastructure.Repository.Repositories.Label; + +internal class LabelRepository : Repository, ILabelRepository +{ + public LabelRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) + { + } +} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/RepositoryHelper.cs b/Masa.Dcc.Infrastructure.Repository/Repositories/RepositoryHelper.cs similarity index 83% rename from src/Services/Masa.Dcc.Service/Infrastructure/Repositories/RepositoryHelper.cs rename to Masa.Dcc.Infrastructure.Repository/Repositories/RepositoryHelper.cs index 00a6b662..17b02df9 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/RepositoryHelper.cs +++ b/Masa.Dcc.Infrastructure.Repository/Repositories/RepositoryHelper.cs @@ -1,9 +1,9 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories; +namespace Masa.Dcc.Infrastructure.Repository.Repositories; -public static class RepositoryHelper +internal static class RepositoryHelper { public static async Task> GetLatestReleaseOfConfigData(this DccDbContext context, List configData) where T : ConfigObjectBase @@ -18,7 +18,7 @@ public static async Task> GetLatestReleaseOfConfigData(this DccDbCont .Select(x => x.OrderByDescending(x => x.CreationTime).FirstOrDefault()).ToListAsync(); foreach (var config in configData) { - var r = group.FirstOrDefault(x => x?.ConfigObjectId == config.ConfigObjectId); + var r = group.Find(x => x?.ConfigObjectId == config.ConfigObjectId); if (r != null) { config.ConfigObject.SetConfigObjectRelease(r); diff --git a/Masa.Dcc.Infrastructure.Repository/_Imports.cs b/Masa.Dcc.Infrastructure.Repository/_Imports.cs new file mode 100644 index 00000000..0443cd2c --- /dev/null +++ b/Masa.Dcc.Infrastructure.Repository/_Imports.cs @@ -0,0 +1,14 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +global using Masa.BuildingBlocks.Ddd.Domain.Repositories; +global using Masa.BuildingBlocks.StackSdks.Pm.Model; +global using Masa.Dcc.Infrastructure.Domain.App.Aggregates; +global using Masa.Dcc.Infrastructure.EFCore; +global using Microsoft.EntityFrameworkCore; +global using Masa.BuildingBlocks.Data.UoW; +global using Masa.Contrib.Ddd.Domain.Repository.EFCore; +global using Masa.Dcc.Infrastructure.Repository.Label; +global using Masa.Dcc.Infrastructure.Repository.App; +global using System.Linq.Expressions; +global using Masa.Dcc.Contracts.Admin; diff --git a/Masa.Dcc.sln b/Masa.Dcc.sln index b9379abd..38da9ed2 100644 --- a/Masa.Dcc.sln +++ b/Masa.Dcc.sln @@ -45,6 +45,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "localfile", "localfile", "{ dapr\localfile\LocalConfig.json = dapr\localfile\LocalConfig.json EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructures", "Infrastructures", "{FBA859E0-1227-4C36-8747-0B3E667C15B8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Dcc.Infrastructure.Domain", "Masa.Dcc.Infrastructure.Domain\Masa.Dcc.Infrastructure.Domain.csproj", "{F006B325-7721-4107-9438-BCB3CB0151B4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Dcc.Infrastructure.EFCore", "Masa.Dcc.Infrastructure.EFCore\Masa.Dcc.Infrastructure.EFCore.csproj", "{830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Dcc.Infrastructure.EFCore.SqlServer", "Masa.Dcc.Infrastructure.EFCore.SqlServer\Masa.Dcc.Infrastructure.EFCore.SqlServer.csproj", "{BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Dcc.Infrastructure.EFCore.PostgreSql", "Masa.Dcc.Infrastructure.EFCore.PostgreSql\Masa.Dcc.Infrastructure.EFCore.PostgreSql.csproj", "{CFAE0971-F172-4182-B66E-B18A87880463}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Dcc.Infrastructure.Repository", "Masa.Dcc.Infrastructure.Repository\Masa.Dcc.Infrastructure.Repository.csproj", "{82E24932-EF7D-45C4-A630-9C17A7DA3141}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,6 +113,46 @@ Global {B5641C73-48CD-47A9-B9F5-78791DC009AF}.Release|Any CPU.Build.0 = Release|Any CPU {B5641C73-48CD-47A9-B9F5-78791DC009AF}.Release|x86.ActiveCfg = Release|Any CPU {B5641C73-48CD-47A9-B9F5-78791DC009AF}.Release|x86.Build.0 = Release|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Debug|x86.ActiveCfg = Debug|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Debug|x86.Build.0 = Debug|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Release|Any CPU.Build.0 = Release|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Release|x86.ActiveCfg = Release|Any CPU + {F006B325-7721-4107-9438-BCB3CB0151B4}.Release|x86.Build.0 = Release|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Debug|x86.ActiveCfg = Debug|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Debug|x86.Build.0 = Debug|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Release|Any CPU.Build.0 = Release|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Release|x86.ActiveCfg = Release|Any CPU + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6}.Release|x86.Build.0 = Release|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Debug|x86.ActiveCfg = Debug|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Debug|x86.Build.0 = Debug|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Release|Any CPU.Build.0 = Release|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Release|x86.ActiveCfg = Release|Any CPU + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4}.Release|x86.Build.0 = Release|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Debug|x86.ActiveCfg = Debug|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Debug|x86.Build.0 = Debug|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Release|Any CPU.Build.0 = Release|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Release|x86.ActiveCfg = Release|Any CPU + {CFAE0971-F172-4182-B66E-B18A87880463}.Release|x86.Build.0 = Release|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Debug|x86.ActiveCfg = Debug|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Debug|x86.Build.0 = Debug|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Release|Any CPU.Build.0 = Release|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Release|x86.ActiveCfg = Release|Any CPU + {82E24932-EF7D-45C4-A630-9C17A7DA3141}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -118,6 +170,12 @@ Global {0287FF66-2169-4529-89DF-22A88E474B74} = {88AD0A79-5286-4C1C-8A58-AAC9E6870CCD} {B5641C73-48CD-47A9-B9F5-78791DC009AF} = {32774681-0D67-48A6-A379-D57015094F85} {278AD74E-6CFB-40D6-A9B1-21E52A174DBD} = {E011B243-0389-468B-B903-83445BED69A4} + {FBA859E0-1227-4C36-8747-0B3E667C15B8} = {92F40AFA-8416-40BE-9893-D35E1924C69D} + {F006B325-7721-4107-9438-BCB3CB0151B4} = {FBA859E0-1227-4C36-8747-0B3E667C15B8} + {830C07E4-3449-4F4E-9DA8-A2D99C64F8A6} = {FBA859E0-1227-4C36-8747-0B3E667C15B8} + {BFCE5DB8-9FBA-46AE-968C-80BE44E1F8C4} = {FBA859E0-1227-4C36-8747-0B3E667C15B8} + {CFAE0971-F172-4182-B66E-B18A87880463} = {FBA859E0-1227-4C36-8747-0B3E667C15B8} + {82E24932-EF7D-45C4-A630-9C17A7DA3141} = {FBA859E0-1227-4C36-8747-0B3E667C15B8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B83BA2BA-19E5-41FB-A92A-16A03DA229E4} diff --git a/src/Services/Masa.Dcc.Service/Application/Label/QueryHandler.cs b/src/Services/Masa.Dcc.Service/Application/Label/QueryHandler.cs index b90a1a2b..46410d52 100644 --- a/src/Services/Masa.Dcc.Service/Application/Label/QueryHandler.cs +++ b/src/Services/Masa.Dcc.Service/Application/Label/QueryHandler.cs @@ -1,28 +1,27 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Application.Label +namespace Masa.Dcc.Service.Admin.Application.Label; + +public class QueryHandler { - public class QueryHandler - { - private readonly ILabelRepository _labelRepository; + private readonly ILabelRepository _labelRepository; - public QueryHandler(ILabelRepository labelRepository) - { - _labelRepository = labelRepository; - } + public QueryHandler(ILabelRepository labelRepository) + { + _labelRepository = labelRepository; + } - [EventHandler] - public async Task GetLabelsAsync(LabelsQuery labelsQuery) - { - IEnumerable labels = new List(); + [EventHandler] + public async Task GetLabelsAsync(LabelsQuery labelsQuery) + { + IEnumerable labels = new List(); - if (string.IsNullOrEmpty(labelsQuery.TypeCode)) - labels = await _labelRepository.GetListAsync(); - else - labels = await _labelRepository.GetListAsync(label => label.TypeCode == labelsQuery.TypeCode); + if (string.IsNullOrEmpty(labelsQuery.TypeCode)) + labels = await _labelRepository.GetListAsync(); + else + labels = await _labelRepository.GetListAsync(label => label.TypeCode == labelsQuery.TypeCode); - labelsQuery.Result = labels.Adapt>(); - } + labelsQuery.Result = labels.Adapt>(); } } diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/App.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/App.cs deleted file mode 100644 index 8e8ff1f9..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/App.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [NotMapped] - public class App - { - public int Id { get; set; } - - public string Name { get; set; } = ""; - - public string Identity { get; set; } = ""; - - public AppTypes Type { get; set; } - - public ServiceTypes ServiceType { get; set; } - - public string Url { get; set; } = ""; - - public string SwaggerUrl { get; set; } = ""; - - public string Description { get; set; } = ""; - - public DateTime CreationTime { get; set; } - - public Guid Creator { get; set; } - - public DateTime ModificationTime { get; set; } - - public Guid Modifier { get; set; } - - private readonly List _appConfigObjects = new(); - public IReadOnlyCollection AppConfigObjects => _appConfigObjects; - - private readonly List _appSecrets = new(); - public IReadOnlyCollection AppSecrets => _appSecrets; - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppConfigObject.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppConfigObject.cs deleted file mode 100644 index e254ce77..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppConfigObject.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("AppConfigObjects")] - public class AppConfigObject : ConfigObjectBase - { - [Comment("AppId")] - [Required] - [Range(1, int.MaxValue)] - public int AppId { get; private set; } - - public AppConfigObject(int appId, int environmentClusterId) - { - EnvironmentClusterId = environmentClusterId; - AppId = appId; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppPin.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppPin.cs deleted file mode 100644 index a4f0194c..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppPin.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - public class AppPin : FullAggregateRoot - { - [Required] - [Range(1, int.MaxValue)] - public int AppId { get; set; } - - public AppPin(int appId) - { - AppId = appId; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppSecret.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppSecret.cs deleted file mode 100644 index 167dafe0..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/AppSecret.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("AppSecrets")] - public class AppSecret : FullAggregateRoot - { - [Required] - [Range(1, int.MaxValue)] - public int AppId { get; private set; } - - [Required] - [Range(1, int.MaxValue)] - public int EnvironmentId { get; private set; } - - [Required] - [Range(1, int.MaxValue)] - public SecretType Type { get; private set; } - - [Required] - public Guid EncryptionSecret { get; private set; } - - [Required] - public Guid Secret { get; private set; } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfig.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfig.cs deleted file mode 100644 index 918d63de..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfig.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("BizConfigs")] - public class BizConfig : FullAggregateRoot - { - [Required] - public string Name { get; private set; } - - [Required] - public string Identity { get; private set; } - - private readonly List _bizConfigObjects = new(); - public IReadOnlyCollection BizConfigObjects => _bizConfigObjects; - - public BizConfig(string name, string identity) - { - Name = name; - Identity = identity; - } - - public void Update(string name) - { - Name = name; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfigObject.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfigObject.cs deleted file mode 100644 index 65660408..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/BizConfigObject.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("BizConfigObjects")] - public class BizConfigObject : ConfigObjectBase - { - [Required] - [Range(1, int.MaxValue)] - public int BizConfigId { get; private set; } - - public BizConfig BizConfig { get; private set; } = null!; - - public BizConfigObject(int bizConfigId, int environmentClusterId) - { - BizConfigId = bizConfigId; - EnvironmentClusterId = environmentClusterId; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObject.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObject.cs deleted file mode 100644 index caf76819..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObject.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("ConfigObjects")] - public class ConfigObject : FullAggregateRoot - { - [Comment("Name")] - [Required(ErrorMessage = "Config object name is required")] - [StringLength(100, MinimumLength = 2, ErrorMessage = "Config object name length range is [2-100]")] - public string Name { get; private set; } - - [Comment("Format")] - [Required(ErrorMessage = "Format Label Code is required")] - [StringLength(100, MinimumLength = 2, ErrorMessage = "Format Label Code length range is [2-100]")] - public string FormatLabelCode { get; private set; } - - [Comment("Type")] - [Range(1, int.MaxValue, ErrorMessage = "Type is required")] - public ConfigObjectType Type { get; private set; } - - [Required] - public bool Encryption { get; private set; } - - [Required] - [Column(TypeName = "ntext")] - public string Content { get; private set; } - - [Required] - [Column(TypeName = "ntext")] - public string TempContent { get; private set; } - - [Comment("Relation config object Id")] - public int RelationConfigObjectId { get; private set; } - - public bool FromRelation { get; private set; } - - public PublicConfigObject PublicConfigObject { get; private set; } = null!; - - public BizConfigObject BizConfigObject { get; set; } = null!; - - public AppConfigObject AppConfigObject { get; private set; } = null!; - - private readonly List _configObjectRelease = new(); - public IReadOnlyCollection ConfigObjectRelease => _configObjectRelease; - - public ConfigObject(string name, string formatLabelCode, ConfigObjectType type, string content, string tempContent, int relationConfigObjectId = 0, bool fromRelation = false, bool encryption = false) - { - Name = name; - FormatLabelCode = formatLabelCode; - Type = type; - Content = content; - TempContent = tempContent; - RelationConfigObjectId = relationConfigObjectId; - FromRelation = fromRelation; - Encryption = encryption; - } - - public void SetConfigObjectType(ConfigObjectType type) - { - Type = type; - } - - public void SetConfigObjectRelease(IEnumerable configObjectReleases) - { - _configObjectRelease.Clear(); - _configObjectRelease.TryAddRange(configObjectReleases); - } - - public void SetConfigObjectRelease(ConfigObjectRelease configObjectRelease) - { - _configObjectRelease.Clear(); - _configObjectRelease.TryAdd(configObjectRelease); - } - - public void UpdateContent(string content) - { - Content = content; - } - - public void AddContent(string content, string tempContent) - { - Content = content; - TempContent = tempContent; - } - - public void SetPublicConfigObject(int publicConfigId, int environmentClusterId) - { - PublicConfigObject = new PublicConfigObject(publicConfigId, environmentClusterId); - } - - public void SetBizConfigObject(int bizId, int environmentClusterId) - { - BizConfigObject = new BizConfigObject(bizId, environmentClusterId); - } - - public void SetAppConfigObject(int appId, int environmentClusterId) - { - AppConfigObject = new AppConfigObject(appId, environmentClusterId); - } - - public void Revoke() - { - Content = TempContent; - } - - public void Relation(int relationConfigObjectId) - { - RelationConfigObjectId = relationConfigObjectId; - FromRelation = true; - } - - public void UnRelation() - { - RelationConfigObjectId = 0; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectRelease.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectRelease.cs deleted file mode 100644 index f65fba97..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/ConfigObjectRelease.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("ConfigObjectReleases")] - public class ConfigObjectRelease : FullAggregateRoot - { - [Comment("Release type")] - [Column(TypeName = "tinyint")] - public ReleaseType Type { get; set; } - - [Comment("Config object Id")] - [Required(ErrorMessage = "Config object Id is required")] - [Range(minimum: 1, maximum: int.MaxValue, ErrorMessage = "Config object Id is required")] - public int ConfigObjectId { get; set; } - - [Comment("Rollback From Release Id")] - public int FromReleaseId { get; set; } - - [Comment("If it is rolled back, it will be true")] - public bool IsInvalid { get; set; } - - [Comment("Version format is yyyyMMddHHmmss")] - [Required(ErrorMessage = "Version is required")] - [Column(TypeName = "varchar(20)")] - public string Version { get; set; } - - [Comment("Name")] - [Required(ErrorMessage = "Name is required", AllowEmptyStrings = true)] - [Column(TypeName = "nvarchar(100)")] - [StringLength(100, MinimumLength = 2, ErrorMessage = "Name length range is [2-100]")] - public string Name { get; set; } - - [Comment("Comment")] - [Required(ErrorMessage = "Comment is required", AllowEmptyStrings = true)] - [Column(TypeName = "nvarchar(500)")] - [StringLength(500, MinimumLength = 0, ErrorMessage = "Comment length range is [0-500]")] - public string Comment { get; set; } - - [Comment("Content")] - [Required(ErrorMessage = "Content is required", AllowEmptyStrings = true)] - [StringLength(int.MaxValue, MinimumLength = 1, ErrorMessage = "Content length range is [1-2147483647]")] - [Column(TypeName = "ntext")] - public string Content { get; set; } - - public ConfigObjectRelease(int configObjectId, string name, string comment, string content, string? version = null, int fromReleaseId = 0, ReleaseType type = ReleaseType.MainRelease) - { - ConfigObjectId = configObjectId; - Name = name; - Comment = comment; - Content = content; - Version = version ?? DateTime.UtcNow.ToString("yyyyMMddHHmmss"); - FromReleaseId = fromReleaseId; - Type = type; - } - - public void Invalid() - { - IsInvalid = true; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfig.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfig.cs deleted file mode 100644 index fc83b2f7..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfig.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("PublicConfigs")] - public class PublicConfig : FullAggregateRoot - { - [Required] - public string Name { get; private set; } - - [Required] - public string Identity { get; private set; } - - [Required] - public string Description { get; private set; } - - private readonly List _publicConfigObjects = new(); - public IReadOnlyCollection PublicConfigObjects => _publicConfigObjects; - - public PublicConfig(string name, string identity, string description = "") - { - Name = name; - Identity = identity; - Description = description; - } - - public void Update(string name, string description) - { - Name = name; - Description = description; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfigObject.cs b/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfigObject.cs deleted file mode 100644 index c162518d..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Aggregates/PublicConfigObject.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Aggregates -{ - [Table("PublicConfigObjects")] - public class PublicConfigObject : ConfigObjectBase - { - [Required] - [Range(1, int.MaxValue)] - public int PublicConfigId { get; private set; } - - public PublicConfig PublicConfig { get; private set; } = null!; - - public PublicConfigObject(int publicConfigId, int environmentClusterId) - { - PublicConfigId = publicConfigId; - EnvironmentClusterId = environmentClusterId; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs deleted file mode 100644 index 1ba2d646..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories -{ - public interface IAppConfigObjectRepository : IRepository - { - Task> GetListByAppIdAsync(int appId); - - Task> GetListByEnvClusterIdAsync(int envClusterId, int appId, bool getLatestRelease = false); - - Task> GetAppLatestReleaseConfigAsync(IEnumerable appIds, - int? envClusterId = null); - - Task GetbyConfigObjectIdAsync(int configObjectId); - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppPinRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppPinRepository.cs deleted file mode 100644 index 4e0db93e..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppPinRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories -{ - public interface IAppPinRepository : IRepository - { - Task> GetListAsync(List appIds); - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs deleted file mode 100644 index c41b1a48..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories -{ - public interface IBizConfigObjectRepository : IRepository - { - Task> GetListByEnvClusterIdAsync(int envClusterId, int bizConfigId, - bool getLatestRelease = false); - - Task> GetListByBizConfigIdAsync(int bizConfigId); - - Task> GetProjectLatestReleaseConfigAsync( - List projects, int? envClusterId = null); - - Task GetByConfigObjectIdAsync(int configObjectId); - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectRepository.cs deleted file mode 100644 index 7afe008f..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IConfigObjectRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories -{ - public interface IConfigObjectRepository : IRepository - { - Task GetConfigObjectWithReleaseHistoriesAsync(int Id); - - Task> GetRelationConfigObjectWithReleaseHistoriesAsync(int Id); - - Task> GetNewestConfigObjectReleaseWithAppInfo(); - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigObjectRepository.cs deleted file mode 100644 index 28deaf18..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IPublicConfigObjectRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.App.Repositories -{ - public interface IPublicConfigObjectRepository : IRepository - { - Task> GetListByEnvClusterIdAsync(int? envClusterId, int publicConfigId, - bool getLatestRelease = false); - - Task GetByConfigObjectIdAsync(int configObjectId); - - Task> GetListByPublicConfigIdAsync(int publicConfigId); - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs b/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs index 292f6439..deb1cad8 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs +++ b/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs @@ -1,678 +1,677 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.App.Services +namespace Masa.Dcc.Service.Admin.Domain.App.Services; + +public class ConfigObjectDomainService : DomainService { - public class ConfigObjectDomainService : DomainService + private readonly DccDbContext _context; + private readonly IConfigObjectReleaseRepository _configObjectReleaseRepository; + private readonly IConfigObjectRepository _configObjectRepository; + private readonly IAppConfigObjectRepository _appConfigObjectRepository; + private readonly IBizConfigObjectRepository _bizConfigObjectRepository; + private readonly IBizConfigRepository _bizConfigRepository; + private readonly IPublicConfigObjectRepository _publicConfigObjectRepository; + private readonly IPublicConfigRepository _publicConfigRepository; + private readonly IMultilevelCacheClient _memoryCacheClient; + private readonly IPmClient _pmClient; + private readonly IMasaStackConfig _masaStackConfig; + private readonly IUnitOfWork _unitOfWork; + private readonly JsonSerializerOptions _jsonSerializerOptions = new() { - private readonly DccDbContext _context; - private readonly IConfigObjectReleaseRepository _configObjectReleaseRepository; - private readonly IConfigObjectRepository _configObjectRepository; - private readonly IAppConfigObjectRepository _appConfigObjectRepository; - private readonly IBizConfigObjectRepository _bizConfigObjectRepository; - private readonly IBizConfigRepository _bizConfigRepository; - private readonly IPublicConfigObjectRepository _publicConfigObjectRepository; - private readonly IPublicConfigRepository _publicConfigRepository; - private readonly IMultilevelCacheClient _memoryCacheClient; - private readonly IPmClient _pmClient; - private readonly IMasaStackConfig _masaStackConfig; - private readonly IUnitOfWork _unitOfWork; - private readonly JsonSerializerOptions _jsonSerializerOptions = new() - { - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - WriteIndented = true - }; + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + WriteIndented = true + }; + + public ConfigObjectDomainService( + IDomainEventBus eventBus, + DccDbContext context, + IConfigObjectReleaseRepository configObjectReleaseRepository, + IConfigObjectRepository configObjectRepository, + IAppConfigObjectRepository appConfigObjectRepository, + IBizConfigObjectRepository bizConfigObjectRepository, + IBizConfigRepository bizConfigRepository, + IPublicConfigObjectRepository publicConfigObjectRepository, + IPublicConfigRepository publicConfigRepository, + IMultilevelCacheClient memoryCacheClient, + IPmClient pmClient, + IMasaStackConfig masaStackConfig, + IUnitOfWork unitOfWork) : base(eventBus) + { + _context = context; + _configObjectReleaseRepository = configObjectReleaseRepository; + _configObjectRepository = configObjectRepository; + _appConfigObjectRepository = appConfigObjectRepository; + _bizConfigObjectRepository = bizConfigObjectRepository; + _bizConfigRepository = bizConfigRepository; + _publicConfigObjectRepository = publicConfigObjectRepository; + _publicConfigRepository = publicConfigRepository; + _memoryCacheClient = memoryCacheClient; + _pmClient = pmClient; + _masaStackConfig = masaStackConfig; + _unitOfWork = unitOfWork; + } - public ConfigObjectDomainService( - IDomainEventBus eventBus, - DccDbContext context, - IConfigObjectReleaseRepository configObjectReleaseRepository, - IConfigObjectRepository configObjectRepository, - IAppConfigObjectRepository appConfigObjectRepository, - IBizConfigObjectRepository bizConfigObjectRepository, - IBizConfigRepository bizConfigRepository, - IPublicConfigObjectRepository publicConfigObjectRepository, - IPublicConfigRepository publicConfigRepository, - IMultilevelCacheClient memoryCacheClient, - IPmClient pmClient, - IMasaStackConfig masaStackConfig, - IUnitOfWork unitOfWork) : base(eventBus) + public async Task AddConfigObjectAsync(List configObjectDtos) + { + List configObjects = new(); + foreach (var configObjectDto in configObjectDtos) { - _context = context; - _configObjectReleaseRepository = configObjectReleaseRepository; - _configObjectRepository = configObjectRepository; - _appConfigObjectRepository = appConfigObjectRepository; - _bizConfigObjectRepository = bizConfigObjectRepository; - _bizConfigRepository = bizConfigRepository; - _publicConfigObjectRepository = publicConfigObjectRepository; - _publicConfigRepository = publicConfigRepository; - _memoryCacheClient = memoryCacheClient; - _pmClient = pmClient; - _masaStackConfig = masaStackConfig; - _unitOfWork = unitOfWork; + var configObject = new ConfigObject( + configObjectDto.Name, + configObjectDto.FormatLabelCode, + configObjectDto.Type, + configObjectDto.Content, + configObjectDto.TempContent, + configObjectDto.RelationConfigObjectId, + configObjectDto.FromRelation, + configObjectDto.Encryption); + + configObjects.Add(configObject); + + if (configObjectDto.Type == ConfigObjectType.Public) + { + configObject.SetPublicConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); + } + else if (configObjectDto.Type == ConfigObjectType.App) + { + configObject.SetAppConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); + } + else if (configObjectDto.Type == ConfigObjectType.Biz) + { + configObject.SetBizConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); + } } - public async Task AddConfigObjectAsync(List configObjectDtos) + await _configObjectRepository.AddRangeAsync(configObjects); + } + + public async Task RemoveConfigObjectAsync(RemoveConfigObjectDto dto) + { + var configObjectEntity = await _configObjectRepository.FindAsync(p => p.Id == dto.ConfigObjectId) + ?? throw new UserFriendlyException("Config object does not exist"); + + await _configObjectRepository.RemoveAsync(configObjectEntity); + + var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.AppId}-{configObjectEntity.Name}"; + await _memoryCacheClient.RemoveAsync(key.ToLower()); + } + + public async Task UpdateConfigObjectContentAsync(UpdateConfigObjectContentDto dto) + { + var configObject = await _configObjectRepository.FindAsync(configObject => configObject.Id == dto.ConfigObjectId) + ?? throw new UserFriendlyException("Config object does not exist"); + + if (dto.FormatLabelCode.Trim().ToLower() != "properties") { - List configObjects = new(); - foreach (var configObjectDto in configObjectDtos) + string content = dto.Content; + if (configObject.Encryption) { - var configObject = new ConfigObject( - configObjectDto.Name, - configObjectDto.FormatLabelCode, - configObjectDto.Type, - configObjectDto.Content, - configObjectDto.TempContent, - configObjectDto.RelationConfigObjectId, - configObjectDto.FromRelation, - configObjectDto.Encryption); - - configObjects.Add(configObject); - - if (configObjectDto.Type == ConfigObjectType.Public) - { - configObject.SetPublicConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); - } - else if (configObjectDto.Type == ConfigObjectType.App) - { - configObject.SetAppConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); - } - else if (configObjectDto.Type == ConfigObjectType.Biz) - { - configObject.SetBizConfigObject(configObjectDto.ObjectId, configObjectDto.EnvironmentClusterId); - } + content = EncryptContent(dto.Content); } - await _configObjectRepository.AddRangeAsync(configObjects); + configObject.UpdateContent(content); + configObject.UnRelation(); } - - public async Task RemoveConfigObjectAsync(RemoveConfigObjectDto dto) + else { - var configObjectEntity = await _configObjectRepository.FindAsync(p => p.Id == dto.ConfigObjectId) - ?? throw new UserFriendlyException("Config object does not exist"); + string content = configObject.Content; + if (configObject.Encryption && configObject.Content != "[]") + { + content = DecryptContent(configObject.Content); + } - await _configObjectRepository.RemoveAsync(configObjectEntity); + var propertyEntities = JsonSerializer.Deserialize>(content) ?? new(); + if (dto.AddConfigObjectPropertyContent.Any()) + { + propertyEntities.AddRange(dto.AddConfigObjectPropertyContent); + } + if (dto.DeleteConfigObjectPropertyContent.Any()) + { + propertyEntities.RemoveAll(prop => dto.DeleteConfigObjectPropertyContent.Select(prop => prop.Key).Contains(prop.Key)); + } + if (dto.EditConfigObjectPropertyContent.Any()) + { + propertyEntities.RemoveAll(prop => dto.EditConfigObjectPropertyContent.Select(prop => prop.Key).Contains(prop.Key)); + propertyEntities.AddRange(dto.EditConfigObjectPropertyContent); + } - var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.AppId}-{configObjectEntity.Name}"; - await _memoryCacheClient.RemoveAsync(key.ToLower()); + content = JsonSerializer.Serialize(propertyEntities, _jsonSerializerOptions); + if (configObject.Encryption) + { + content = EncryptContent(content); + } + configObject.UpdateContent(content); } - public async Task UpdateConfigObjectContentAsync(UpdateConfigObjectContentDto dto) - { - var configObject = await _configObjectRepository.FindAsync(configObject => configObject.Id == dto.ConfigObjectId) - ?? throw new UserFriendlyException("Config object does not exist"); + await _configObjectRepository.UpdateAsync(configObject); + } - if (dto.FormatLabelCode.Trim().ToLower() != "properties") - { - string content = dto.Content; - if (configObject.Encryption) - { - content = EncryptContent(dto.Content); - } + private string EncryptContent(string content) + { + var secret = _masaStackConfig.DccSecret; - configObject.UpdateContent(content); - configObject.UnRelation(); - } - else - { - string content = configObject.Content; - if (configObject.Encryption && configObject.Content != "[]") - { - content = DecryptContent(configObject.Content); - } + var encryptContent = AesUtils.Encrypt(content, secret, FillType.Left); + return encryptContent; + } - var propertyEntities = JsonSerializer.Deserialize>(content) ?? new(); - if (dto.AddConfigObjectPropertyContent.Any()) - { - propertyEntities.AddRange(dto.AddConfigObjectPropertyContent); - } - if (dto.DeleteConfigObjectPropertyContent.Any()) - { - propertyEntities.RemoveAll(prop => dto.DeleteConfigObjectPropertyContent.Select(prop => prop.Key).Contains(prop.Key)); - } - if (dto.EditConfigObjectPropertyContent.Any()) - { - propertyEntities.RemoveAll(prop => dto.EditConfigObjectPropertyContent.Select(prop => prop.Key).Contains(prop.Key)); - propertyEntities.AddRange(dto.EditConfigObjectPropertyContent); - } + private string DecryptContent(string content) + { + var secret = _masaStackConfig.DccSecret; - content = JsonSerializer.Serialize(propertyEntities, _jsonSerializerOptions); - if (configObject.Encryption) - { - content = EncryptContent(content); - } - configObject.UpdateContent(content); - } + var encryptContent = AesUtils.Decrypt(content, secret, FillType.Left); + return encryptContent; + } - await _configObjectRepository.UpdateAsync(configObject); - } + public async Task CloneConfigObjectAsync(CloneConfigObjectDto dto) + { + //add + await CheckConfigObjectDuplication(dto.ConfigObjects, dto.ToObjectId); + await CloneConfigObjectsAsync(dto.ConfigObjects, dto.ToObjectId); - private string EncryptContent(string content) - { - var secret = _masaStackConfig.DccSecret; + //update + var envClusterIds = dto.CoverConfigObjects.Select(c => c.EnvironmentClusterId); + var configNames = dto.CoverConfigObjects.Select(c => c.Name).Distinct(); - var encryptContent = AesUtils.Encrypt(content, secret, FillType.Left); - return encryptContent; + IEnumerable needEditConfig = new List(); + if (dto.ConfigObjectType == ConfigObjectType.App) + { + var appConfigObjects = await _appConfigObjectRepository.GetListAsync( + app => app.AppId == dto.ToObjectId && envClusterIds.Contains(app.EnvironmentClusterId)); + needEditConfig = await _configObjectRepository.GetListAsync(c => appConfigObjects.Select(app => app.ConfigObjectId).Contains(c.Id) && configNames.Contains(c.Name)); } - - private string DecryptContent(string content) + else if (dto.ConfigObjectType == ConfigObjectType.Biz) { - var secret = _masaStackConfig.DccSecret; - - var encryptContent = AesUtils.Decrypt(content, secret, FillType.Left); - return encryptContent; + var bizConfigObjects = await _bizConfigObjectRepository.GetListAsync( + biz => biz.BizConfigId == dto.ToObjectId && envClusterIds.Contains(biz.EnvironmentClusterId)); + needEditConfig = await _configObjectRepository.GetListAsync(c => bizConfigObjects.Select(biz => biz.ConfigObjectId).Contains(c.Id) && configNames.Contains(c.Name)); } - - public async Task CloneConfigObjectAsync(CloneConfigObjectDto dto) + else if (dto.ConfigObjectType == ConfigObjectType.Public) { - //add - await CheckConfigObjectDuplication(dto.ConfigObjects, dto.ToObjectId); - await CloneConfigObjectsAsync(dto.ConfigObjects, dto.ToObjectId); + var publicConfigObjects = await _publicConfigObjectRepository.GetListAsync( + publicConfig => publicConfig.PublicConfigId == dto.ToObjectId && envClusterIds.Contains(publicConfig.EnvironmentClusterId)); + var s = await _configObjectRepository.GetListAsync(c => publicConfigObjects.Select(publicConfig => publicConfig.ConfigObjectId).Contains(c.Id)); + var ss = publicConfigObjects.Select(publicConfig => publicConfig.ConfigObjectId); + needEditConfig = await _configObjectRepository.GetListAsync(c => ss.Contains(c.Id) && configNames.Contains(c.Name)); + } - //update - var envClusterIds = dto.CoverConfigObjects.Select(c => c.EnvironmentClusterId); - var configNames = dto.CoverConfigObjects.Select(c => c.Name).Distinct(); + foreach (var editConfig in needEditConfig) + { + dto.CoverConfigObjects.ForEach(configObject => + { + if (editConfig.Type == configObject.Type && editConfig.Name.Equals(configObject.Name)) + { + string tempontent = editConfig.FormatLabelCode.ToLower() switch + { + "json" => "{}", + "properties" => "[]", + _ => "", + }; + editConfig.AddContent(configObject.Content, tempontent); + } + }); + } + await _configObjectRepository.UpdateRangeAsync(needEditConfig); + } - IEnumerable needEditConfig = new List(); - if (dto.ConfigObjectType == ConfigObjectType.App) + private async Task CloneConfigObjectsAsync(List configObjects, int appId) + { + List cloneConfigObjects = new(); + foreach (var configObjectDto in configObjects) + { + var configObject = new ConfigObject( + configObjectDto.Name, + configObjectDto.FormatLabelCode, + configObjectDto.Type, + configObjectDto.Content, + configObjectDto.TempContent, + encryption: configObjectDto.Encryption); + cloneConfigObjects.Add(configObject); + + if (configObjectDto.Type == ConfigObjectType.Public) { - var appConfigObjects = await _appConfigObjectRepository.GetListAsync( - app => app.AppId == dto.ToObjectId && envClusterIds.Contains(app.EnvironmentClusterId)); - needEditConfig = await _configObjectRepository.GetListAsync(c => appConfigObjects.Select(app => app.ConfigObjectId).Contains(c.Id) && configNames.Contains(c.Name)); + configObject.SetPublicConfigObject(appId, configObjectDto.EnvironmentClusterId); } - else if (dto.ConfigObjectType == ConfigObjectType.Biz) + else if (configObjectDto.Type == ConfigObjectType.App) { - var bizConfigObjects = await _bizConfigObjectRepository.GetListAsync( - biz => biz.BizConfigId == dto.ToObjectId && envClusterIds.Contains(biz.EnvironmentClusterId)); - needEditConfig = await _configObjectRepository.GetListAsync(c => bizConfigObjects.Select(biz => biz.ConfigObjectId).Contains(c.Id) && configNames.Contains(c.Name)); + configObject.SetAppConfigObject(appId, configObjectDto.EnvironmentClusterId); } - else if (dto.ConfigObjectType == ConfigObjectType.Public) + else if (configObjectDto.Type == ConfigObjectType.Biz) { - var publicConfigObjects = await _publicConfigObjectRepository.GetListAsync( - publicConfig => publicConfig.PublicConfigId == dto.ToObjectId && envClusterIds.Contains(publicConfig.EnvironmentClusterId)); - var s = await _configObjectRepository.GetListAsync(c => publicConfigObjects.Select(publicConfig => publicConfig.ConfigObjectId).Contains(c.Id)); - var ss = publicConfigObjects.Select(publicConfig => publicConfig.ConfigObjectId); - needEditConfig = await _configObjectRepository.GetListAsync(c => ss.Contains(c.Id) && configNames.Contains(c.Name)); + configObject.SetBizConfigObject(appId, configObjectDto.EnvironmentClusterId); } - foreach (var editConfig in needEditConfig) - { - dto.CoverConfigObjects.ForEach(configObject => - { - if (editConfig.Type == configObject.Type && editConfig.Name.Equals(configObject.Name)) - { - string tempontent = editConfig.FormatLabelCode.ToLower() switch - { - "json" => "{}", - "properties" => "[]", - _ => "", - }; - editConfig.AddContent(configObject.Content, tempontent); - } - }); - } - await _configObjectRepository.UpdateRangeAsync(needEditConfig); - } - - private async Task CloneConfigObjectsAsync(List configObjects, int appId) - { - List cloneConfigObjects = new(); - foreach (var configObjectDto in configObjects) + if (configObject.Encryption) { - var configObject = new ConfigObject( - configObjectDto.Name, - configObjectDto.FormatLabelCode, - configObjectDto.Type, - configObjectDto.Content, - configObjectDto.TempContent, - encryption: configObjectDto.Encryption); - cloneConfigObjects.Add(configObject); - - if (configObjectDto.Type == ConfigObjectType.Public) - { - configObject.SetPublicConfigObject(appId, configObjectDto.EnvironmentClusterId); - } - else if (configObjectDto.Type == ConfigObjectType.App) - { - configObject.SetAppConfigObject(appId, configObjectDto.EnvironmentClusterId); - } - else if (configObjectDto.Type == ConfigObjectType.Biz) - { - configObject.SetBizConfigObject(appId, configObjectDto.EnvironmentClusterId); - } - - if (configObject.Encryption) - { - var encryptConten = EncryptContent(configObject.Content); - configObject.UpdateContent(encryptConten); - } + var encryptConten = EncryptContent(configObject.Content); + configObject.UpdateContent(encryptConten); } - await _configObjectRepository.AddRangeAsync(cloneConfigObjects); } + await _configObjectRepository.AddRangeAsync(cloneConfigObjects); + } - private async Task CheckConfigObjectDuplication(List configObjects, int appId) + private async Task CheckConfigObjectDuplication(List configObjects, int appId) + { + if (configObjects?.Count > 0) { - if (configObjects?.Count > 0) + var configType = configObjects.First().Type; + var configObjectNames = configObjects.Select(e => e.Name); + switch (configType) { - var configType = configObjects.First().Type; - var configObjectNames = configObjects.Select(e => e.Name); - switch (configType) - { - case ConfigObjectType.Public: - var allPublicConfigs = await _publicConfigObjectRepository.GetListByPublicConfigIdAsync(appId); - foreach (var item in configObjects) + case ConfigObjectType.Public: + var allPublicConfigs = await _publicConfigObjectRepository.GetListByPublicConfigIdAsync(appId); + foreach (var item in configObjects) + { + if (allPublicConfigs.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) { - if (allPublicConfigs.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) - { - throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist in the environment cluster '{item.EnvironmentClusterId}'."); - } + throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist in the environment cluster '{item.EnvironmentClusterId}'."); } - break; - case ConfigObjectType.Biz: - var bizConfigObjects = await _bizConfigObjectRepository.GetListByBizConfigIdAsync(appId); - foreach (var item in configObjects) + } + break; + case ConfigObjectType.Biz: + var bizConfigObjects = await _bizConfigObjectRepository.GetListByBizConfigIdAsync(appId); + foreach (var item in configObjects) + { + if (bizConfigObjects.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) { - if (bizConfigObjects.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) - { - throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist in the environment cluster '{item.EnvironmentClusterId}'."); - } + throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist in the environment cluster '{item.EnvironmentClusterId}'."); } - break; - case ConfigObjectType.App: - var allAppConfigObjects = await _appConfigObjectRepository.GetListByAppIdAsync(appId); - foreach (var item in configObjects) + } + break; + case ConfigObjectType.App: + var allAppConfigObjects = await _appConfigObjectRepository.GetListByAppIdAsync(appId); + foreach (var item in configObjects) + { + if (allAppConfigObjects.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) { - if (allAppConfigObjects.Any(e => e.EnvironmentClusterId == item.EnvironmentClusterId && e.ConfigObject.Name == item.Name)) - { - throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist for environment cluster's '{item.EnvironmentClusterId}'. "); - } + throw new UserFriendlyException($"Configuration Name '{item.Name}' already exist for environment cluster's '{item.EnvironmentClusterId}'. "); } - break; - } + } + break; } } + } - public async Task AddConfigObjectReleaseAsync(AddConfigObjectReleaseDto dto) - { - var configObject = (await _configObjectRepository.FindAsync( - configObject => configObject.Id == dto.ConfigObjectId)) ?? throw new Exception("Config object does not exist"); + public async Task AddConfigObjectReleaseAsync(AddConfigObjectReleaseDto dto) + { + var configObject = (await _configObjectRepository.FindAsync( + configObject => configObject.Id == dto.ConfigObjectId)) ?? throw new Exception("Config object does not exist"); + + configObject.AddContent(configObject.Content, configObject.Content); + await _configObjectRepository.UpdateAsync(configObject); - configObject.AddContent(configObject.Content, configObject.Content); - await _configObjectRepository.UpdateAsync(configObject); + var configObjectRelease = new ConfigObjectRelease( + dto.ConfigObjectId, + dto.Name, + dto.Comment, + configObject.Content); + await _configObjectReleaseRepository.AddAsync(configObjectRelease); - var configObjectRelease = new ConfigObjectRelease( - dto.ConfigObjectId, - dto.Name, - dto.Comment, - configObject.Content); - await _configObjectReleaseRepository.AddAsync(configObjectRelease); + var relationConfigObjects = await _configObjectRepository.GetRelationConfigObjectWithReleaseHistoriesAsync(configObject.Id); + if (relationConfigObjects.Any()) + { + var allEnvClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); + var appConfigObjects = await _appConfigObjectRepository.GetListAsync(app => relationConfigObjects.Select(c => c.Id).Contains(app.ConfigObjectId)); + var apps = await _pmClient.AppService.GetListAsync(); - var relationConfigObjects = await _configObjectRepository.GetRelationConfigObjectWithReleaseHistoriesAsync(configObject.Id); - if (relationConfigObjects.Any()) + foreach (var item in appConfigObjects) { - var allEnvClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); - var appConfigObjects = await _appConfigObjectRepository.GetListAsync(app => relationConfigObjects.Select(c => c.Id).Contains(app.ConfigObjectId)); - var apps = await _pmClient.AppService.GetListAsync(); + var envCluster = allEnvClusters.FirstOrDefault(c => c.Id == item.EnvironmentClusterId) ?? new(); + var app = apps.FirstOrDefault(a => a.Id == item.AppId) ?? new(); + var relationConfigObject = relationConfigObjects.First(c => c.Id == item.ConfigObjectId); + var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{relationConfigObject.Name}"; - foreach (var item in appConfigObjects) + if (relationConfigObject.FormatLabelCode.ToLower() == "properties") { - var envCluster = allEnvClusters.FirstOrDefault(c => c.Id == item.EnvironmentClusterId) ?? new(); - var app = apps.FirstOrDefault(a => a.Id == item.AppId) ?? new(); - var relationConfigObject = relationConfigObjects.First(c => c.Id == item.ConfigObjectId); - var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{relationConfigObject.Name}"; - - if (relationConfigObject.FormatLabelCode.ToLower() == "properties") + var appRelease = relationConfigObject.ConfigObjectRelease.OrderByDescending(c => c.Id).FirstOrDefault(); + if (appRelease == null) { - var appRelease = relationConfigObject.ConfigObjectRelease.OrderByDescending(c => c.Id).FirstOrDefault(); - if (appRelease == null) - { - await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel - { - Content = dto.Content, - FormatLabelCode = configObject.FormatLabelCode, - Encryption = configObject.Encryption - }); - } - else + await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel { - //compare - var publicContents = JsonSerializer.Deserialize>(dto.Content) ?? new(); - var appContents = JsonSerializer.Deserialize>(appRelease.Content) ?? new(); - - var exceptContent = publicContents.ExceptBy(appContents.Select(c => c.Key), content => content.Key).ToList(); - var content = appContents.Union(exceptContent).ToList(); - - var releaseContent = new PublishReleaseModel - { - Content = JsonSerializer.Serialize(content, _jsonSerializerOptions), - FormatLabelCode = configObject.FormatLabelCode, - Encryption = configObject.Encryption - }; - await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); - } + Content = dto.Content, + FormatLabelCode = configObject.FormatLabelCode, + Encryption = configObject.Encryption + }); } else { + //compare + var publicContents = JsonSerializer.Deserialize>(dto.Content) ?? new(); + var appContents = JsonSerializer.Deserialize>(appRelease.Content) ?? new(); + + var exceptContent = publicContents.ExceptBy(appContents.Select(c => c.Key), content => content.Key).ToList(); + var content = appContents.Union(exceptContent).ToList(); + var releaseContent = new PublishReleaseModel { - Content = dto.Content, + Content = JsonSerializer.Serialize(content, _jsonSerializerOptions), FormatLabelCode = configObject.FormatLabelCode, Encryption = configObject.Encryption }; await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); } } - } - else - { - //add redis cache - var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.Identity}-{configObject.Name}"; - if (configObject.Encryption) + else { - dto.Content = EncryptContent(dto.Content); + var releaseContent = new PublishReleaseModel + { + Content = dto.Content, + FormatLabelCode = configObject.FormatLabelCode, + Encryption = configObject.Encryption + }; + await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); } - var releaseContent = new PublishReleaseModel - { - Content = dto.Content, - FormatLabelCode = configObject.FormatLabelCode, - Encryption = configObject.Encryption - }; - await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); } } - - public async Task RollbackConfigObjectReleaseAsync(RollbackConfigObjectReleaseDto rollbackDto) + else { - var latestConfigObjectRelease = await _context.Set() - .Where(cor => cor.ConfigObjectId == rollbackDto.ConfigObjectId) - .OrderByDescending(cor => cor.Id) - .FirstOrDefaultAsync(); - - var rollbackToEntity = await _configObjectReleaseRepository.FindAsync( - ocr => ocr.Id == rollbackDto.RollbackToReleaseId); - - if (latestConfigObjectRelease == null || rollbackToEntity == null) - { - throw new Exception("要回滚的版本不存在"); - } - - if (rollbackDto.RollbackToReleaseId == latestConfigObjectRelease.FromReleaseId) - { - throw new UserFriendlyException("该版本已作废"); - } - if (rollbackToEntity.Version == latestConfigObjectRelease.Version) - { - throw new UserFriendlyException("两个版本相同"); - } - - //rollback - //add - await _configObjectReleaseRepository.AddAsync(new ConfigObjectRelease( - rollbackToEntity.ConfigObjectId, - rollbackToEntity.Name, - $"由 {latestConfigObjectRelease.Name} 回滚至 {rollbackToEntity.Name}", - rollbackToEntity.Content, - rollbackToEntity.Version, - latestConfigObjectRelease.Id - )); - - //Invalid rollback entity - latestConfigObjectRelease.Invalid(); - await _configObjectReleaseRepository.UpdateAsync(latestConfigObjectRelease); - - //Update ConfigObject entity - var configObject = (await _configObjectRepository.FindAsync(config => config.Id == rollbackDto.ConfigObjectId))!; - configObject.AddContent(configObject.Content, rollbackToEntity.Content); - await _configObjectRepository.UpdateAsync(configObject); - - string key = string.Empty; - var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); - if (configObject.Type == ConfigObjectType.Public) - { - var publicConfigObject = await _publicConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); - var publicConfig = await _publicConfigRepository.FindAsync(c => c.Id == publicConfigObject.PublicConfigId) ?? throw new MasaException(); - var envCluster = envClusters.First(e => e.Id == publicConfigObject.EnvironmentClusterId); - key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{configObject.Name}"; - } - else if (configObject.Type == ConfigObjectType.Biz) - { - var bizConfigObject = await _bizConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); - var bizConfig = await _bizConfigRepository.FindAsync(c => c.Id == bizConfigObject.BizConfigId) ?? throw new MasaException(); - var envCluster = envClusters.First(e => e.Id == bizConfigObject.EnvironmentClusterId); - key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{bizConfig.Identity}-{configObject.Name}"; - } - else if (configObject.Type == ConfigObjectType.App) + //add redis cache + var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.Identity}-{configObject.Name}"; + if (configObject.Encryption) { - var appConfigObject = await _appConfigObjectRepository.GetbyConfigObjectIdAsync(configObject.Id); - var app = await _pmClient.AppService.GetAsync(appConfigObject.AppId) ?? throw new MasaException(); ; - var envCluster = envClusters.First(e => e.Id == appConfigObject.EnvironmentClusterId); - key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{configObject.Name}"; + dto.Content = EncryptContent(dto.Content); } - var releaseContent = new PublishReleaseModel { - Content = configObject.Encryption ? EncryptContent(rollbackToEntity.Content) : rollbackToEntity.Content, + Content = dto.Content, FormatLabelCode = configObject.FormatLabelCode, Encryption = configObject.Encryption }; await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); } + } + + public async Task RollbackConfigObjectReleaseAsync(RollbackConfigObjectReleaseDto rollbackDto) + { + var latestConfigObjectRelease = await _context.Set() + .Where(cor => cor.ConfigObjectId == rollbackDto.ConfigObjectId) + .OrderByDescending(cor => cor.Id) + .FirstOrDefaultAsync(); - public async Task UpdateConfigObjectAsync( - string environmentName, - string clusterName, - string appId, - string configObjectName, - string value) + var rollbackToEntity = await _configObjectReleaseRepository.FindAsync( + ocr => ocr.Id == rollbackDto.RollbackToReleaseId); + + if (latestConfigObjectRelease == null || rollbackToEntity == null) { - var configObjects = await _configObjectRepository.GetListAsync(config => config.Name == configObjectName); - if (!configObjects.Any()) - { - throw new UserFriendlyException("ConfigObject does not exist"); - } + throw new Exception("要回滚的版本不存在"); + } - var environmentClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); - var environmentCluster = environmentClusters.FirstOrDefault(ec => ec.EnvironmentName.ToLower() == environmentName.ToLower() && ec.ClusterName.ToLower() == clusterName.ToLower()) - ?? throw new UserFriendlyException("Environment cluster does not exist"); + if (rollbackDto.RollbackToReleaseId == latestConfigObjectRelease.FromReleaseId) + { + throw new UserFriendlyException("该版本已作废"); + } + if (rollbackToEntity.Version == latestConfigObjectRelease.Version) + { + throw new UserFriendlyException("两个版本相同"); + } - ConfigObject? configObject = null; + //rollback + //add + await _configObjectReleaseRepository.AddAsync(new ConfigObjectRelease( + rollbackToEntity.ConfigObjectId, + rollbackToEntity.Name, + $"由 {latestConfigObjectRelease.Name} 回滚至 {rollbackToEntity.Name}", + rollbackToEntity.Content, + rollbackToEntity.Version, + latestConfigObjectRelease.Id + )); + + //Invalid rollback entity + latestConfigObjectRelease.Invalid(); + await _configObjectReleaseRepository.UpdateAsync(latestConfigObjectRelease); + + //Update ConfigObject entity + var configObject = (await _configObjectRepository.FindAsync(config => config.Id == rollbackDto.ConfigObjectId))!; + configObject.AddContent(configObject.Content, rollbackToEntity.Content); + await _configObjectRepository.UpdateAsync(configObject); + + string key = string.Empty; + var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); + if (configObject.Type == ConfigObjectType.Public) + { + var publicConfigObject = await _publicConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); + var publicConfig = await _publicConfigRepository.FindAsync(c => c.Id == publicConfigObject.PublicConfigId) ?? throw new MasaException(); + var envCluster = envClusters.First(e => e.Id == publicConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{configObject.Name}"; + } + else if (configObject.Type == ConfigObjectType.Biz) + { + var bizConfigObject = await _bizConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); + var bizConfig = await _bizConfigRepository.FindAsync(c => c.Id == bizConfigObject.BizConfigId) ?? throw new MasaException(); + var envCluster = envClusters.First(e => e.Id == bizConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{bizConfig.Identity}-{configObject.Name}"; + } + else if (configObject.Type == ConfigObjectType.App) + { + var appConfigObject = await _appConfigObjectRepository.GetbyConfigObjectIdAsync(configObject.Id); + var app = await _pmClient.AppService.GetAsync(appConfigObject.AppId) ?? throw new MasaException(); ; + var envCluster = envClusters.First(e => e.Id == appConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{configObject.Name}"; + } - var publicConfig = await _publicConfigRepository.FindAsync(p => p.Identity.ToLower() == appId.ToLower()); - if (publicConfig == null) - { - var appDetail = await _pmClient.AppService.GetByIdentityAsync(appId); - var appConfigObjects = await _appConfigObjectRepository.GetListByEnvClusterIdAsync(environmentCluster.Id, appDetail.Id); - configObject = configObjects.FirstOrDefault(c => appConfigObjects.Select(ac => ac.ConfigObjectId).Contains(c.Id)) ?? throw new UserFriendlyException("ConfigObject does not exist"); - } - else - { - var publicConfigObjects = await _publicConfigObjectRepository.GetListByEnvClusterIdAsync(environmentCluster.Id, publicConfig.Id); - configObject = configObjects.FirstOrDefault(c => publicConfigObjects.Select(ac => ac.ConfigObjectId).Contains(c.Id)) ?? throw new UserFriendlyException("ConfigObject does not exist"); - } + var releaseContent = new PublishReleaseModel + { + Content = configObject.Encryption ? EncryptContent(rollbackToEntity.Content) : rollbackToEntity.Content, + FormatLabelCode = configObject.FormatLabelCode, + Encryption = configObject.Encryption + }; + await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); + } - if (configObject.Encryption) - { - value = EncryptContent(value); - } - configObject.UpdateContent(value); - await _configObjectRepository.UpdateAsync(configObject); + public async Task UpdateConfigObjectAsync( + string environmentName, + string clusterName, + string appId, + string configObjectName, + string value) + { + var configObjects = await _configObjectRepository.GetListAsync(config => config.Name == configObjectName); + if (!configObjects.Any()) + { + throw new UserFriendlyException("ConfigObject does not exist"); + } - var releaseModel = new AddConfigObjectReleaseDto - { - Type = ReleaseType.MainRelease, - ConfigObjectId = configObject.Id, - Name = "通过Sdk发布", - EnvironmentName = environmentName, - ClusterName = clusterName, - Identity = appId, - Content = value - }; + var environmentClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); + var environmentCluster = environmentClusters.FirstOrDefault(ec => ec.EnvironmentName.ToLower() == environmentName.ToLower() && ec.ClusterName.ToLower() == clusterName.ToLower()) + ?? throw new UserFriendlyException("Environment cluster does not exist"); - await AddConfigObjectReleaseAsync(releaseModel); + ConfigObject? configObject = null; + + var publicConfig = await _publicConfigRepository.FindAsync(p => p.Identity.ToLower() == appId.ToLower()); + if (publicConfig == null) + { + var appDetail = await _pmClient.AppService.GetByIdentityAsync(appId); + var appConfigObjects = await _appConfigObjectRepository.GetListByEnvClusterIdAsync(environmentCluster.Id, appDetail.Id); + configObject = configObjects.FirstOrDefault(c => appConfigObjects.Select(ac => ac.ConfigObjectId).Contains(c.Id)) ?? throw new UserFriendlyException("ConfigObject does not exist"); + } + else + { + var publicConfigObjects = await _publicConfigObjectRepository.GetListByEnvClusterIdAsync(environmentCluster.Id, publicConfig.Id); + configObject = configObjects.FirstOrDefault(c => publicConfigObjects.Select(ac => ac.ConfigObjectId).Contains(c.Id)) ?? throw new UserFriendlyException("ConfigObject does not exist"); + } + + if (configObject.Encryption) + { + value = EncryptContent(value); } + configObject.UpdateContent(value); + await _configObjectRepository.UpdateAsync(configObject); - public async Task InitConfigObjectAsync( - string environmentName, - string clusterName, - string appId, - Dictionary configObjects, - ConfigObjectType configObjectType = ConfigObjectType.App, - bool isEncryption = false) + var releaseModel = new AddConfigObjectReleaseDto { - var envs = await _pmClient.EnvironmentService.GetListAsync(); - var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist"); - var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id); - var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist"); - foreach (var configObject in configObjects) + Type = ReleaseType.MainRelease, + ConfigObjectId = configObject.Id, + Name = "通过Sdk发布", + EnvironmentName = environmentName, + ClusterName = clusterName, + Identity = appId, + Content = value + }; + + await AddConfigObjectReleaseAsync(releaseModel); + } + + public async Task InitConfigObjectAsync( + string environmentName, + string clusterName, + string appId, + Dictionary configObjects, + ConfigObjectType configObjectType = ConfigObjectType.App, + bool isEncryption = false) + { + var envs = await _pmClient.EnvironmentService.GetListAsync(); + var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist"); + var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id); + var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist"); + foreach (var configObject in configObjects) + { + var configObjectName = configObject.Key; + var key = $"{environmentName}-{clusterName}-{appId}-{configObjectName}".ToLower(); + var redisData = await _memoryCacheClient.GetAsync(key); + if (redisData != null) { - var configObjectName = configObject.Key; - var key = $"{environmentName}-{clusterName}-{appId}-{configObjectName}".ToLower(); - var redisData = await _memoryCacheClient.GetAsync(key); - if (redisData != null) - { - continue; - } + continue; + } - string content = configObject.Value; - if (isEncryption) - content = EncryptContent(content); + string content = configObject.Value; + if (isEncryption) + content = EncryptContent(content); - var newConfigObject = new ConfigObject( - configObjectName, - "JSON", - configObjectType, - content, - "{}", - encryption: isEncryption); + var newConfigObject = new ConfigObject( + configObjectName, + "JSON", + configObjectType, + content, + "{}", + encryption: isEncryption); - var publicConfig = await _publicConfigRepository.FindAsync(publicConfig => publicConfig.Identity == appId); - if (publicConfig != null) + var publicConfig = await _publicConfigRepository.FindAsync(publicConfig => publicConfig.Identity == appId); + if (publicConfig != null) + { + newConfigObject.SetConfigObjectType(ConfigObjectType.App); + newConfigObject.SetPublicConfigObject(publicConfig.Id, cluster.EnvironmentClusterId); + } + else + { + var bizConfig = await _bizConfigRepository.FindAsync(bizConfig => bizConfig.Identity == appId); + if (bizConfig != null) { - newConfigObject.SetConfigObjectType(ConfigObjectType.App); - newConfigObject.SetPublicConfigObject(publicConfig.Id, cluster.EnvironmentClusterId); + newConfigObject.SetConfigObjectType(ConfigObjectType.Biz); + newConfigObject.SetBizConfigObject(bizConfig.Id, cluster.EnvironmentClusterId); } else { - var bizConfig = await _bizConfigRepository.FindAsync(bizConfig => bizConfig.Identity == appId); - if (bizConfig != null) + newConfigObject.SetConfigObjectType(ConfigObjectType.App); + var app = await _pmClient.AppService.GetByIdentityAsync(appId); + if (app != null) { - newConfigObject.SetConfigObjectType(ConfigObjectType.Biz); - newConfigObject.SetBizConfigObject(bizConfig.Id, cluster.EnvironmentClusterId); + newConfigObject.SetAppConfigObject(app.Id, cluster.EnvironmentClusterId); } else { - newConfigObject.SetConfigObjectType(ConfigObjectType.App); - var app = await _pmClient.AppService.GetByIdentityAsync(appId); - if (app != null) - { - newConfigObject.SetAppConfigObject(app.Id, cluster.EnvironmentClusterId); - } - else - { - throw new UserFriendlyException("AppId Error"); - } + throw new UserFriendlyException("AppId Error"); } } - await _configObjectRepository.AddAsync(newConfigObject); - await _unitOfWork.SaveChangesAsync(); - - var releaseModel = new AddConfigObjectReleaseDto - { - Type = ReleaseType.MainRelease, - ConfigObjectId = newConfigObject.Id, - Name = "通过Sdk发布", - EnvironmentName = environmentName, - ClusterName = clusterName, - Identity = appId, - Content = configObject.Value - }; - await AddConfigObjectReleaseAsync(releaseModel); } + await _configObjectRepository.AddAsync(newConfigObject); + await _unitOfWork.SaveChangesAsync(); + + var releaseModel = new AddConfigObjectReleaseDto + { + Type = ReleaseType.MainRelease, + ConfigObjectId = newConfigObject.Id, + Name = "通过Sdk发布", + EnvironmentName = environmentName, + ClusterName = clusterName, + Identity = appId, + Content = configObject.Value + }; + await AddConfigObjectReleaseAsync(releaseModel); } + } - public async Task RefreshConfigObjectToRedisAsync() - { - var configObjectInfo = await _configObjectRepository.GetNewestConfigObjectReleaseWithAppInfo(); - var apps = await _pmClient.AppService.GetListAsync(); - var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); - var publicConfig = (await _publicConfigRepository.GetListAsync()).FirstOrDefault() - ?? throw new UserFriendlyException("PublicConfig is null"); + public async Task RefreshConfigObjectToRedisAsync() + { + var configObjectInfo = await _configObjectRepository.GetNewestConfigObjectReleaseWithAppInfo(); + var apps = await _pmClient.AppService.GetListAsync(); + var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); + var publicConfig = (await _publicConfigRepository.GetListAsync()).FirstOrDefault() + ?? throw new UserFriendlyException("PublicConfig is null"); - configObjectInfo.ForEach(config => + configObjectInfo.ForEach(config => + { + if (config.ConfigObject.Type == ConfigObjectType.App) { - if (config.ConfigObject.Type == ConfigObjectType.App) + apps.Where(app => app.Id == config.ObjectId).ToList().ForEach(app => { - apps.Where(app => app.Id == config.ObjectId).ToList().ForEach(app => + app.EnvironmentClusters.ForEach(async envCluster => { - app.EnvironmentClusters.ForEach(async envCluster => + if (envCluster.Id == config.EnvironmentClusterId) { - if (envCluster.Id == config.EnvironmentClusterId) + var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{config.ConfigObject.Name}"; + await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel { - var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{config.ConfigObject.Name}"; - await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel - { - Content = config.ConfigObject.Content, - FormatLabelCode = config.ConfigObject.FormatLabelCode, - Encryption = config.ConfigObject.Encryption - }); - } - }); + Content = config.ConfigObject.Content, + FormatLabelCode = config.ConfigObject.FormatLabelCode, + Encryption = config.ConfigObject.Encryption + }); + } }); - } - else if (config.ConfigObject.Type == ConfigObjectType.Public) + }); + } + else if (config.ConfigObject.Type == ConfigObjectType.Public) + { + envClusters.Where(ec => ec.Id == config.EnvironmentClusterId).ToList().ForEach(async envCluster => { - envClusters.Where(ec => ec.Id == config.EnvironmentClusterId).ToList().ForEach(async envCluster => + var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{config.ConfigObject.Name}"; + await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel { - var key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{config.ConfigObject.Name}"; - await _memoryCacheClient.SetAsync(key.ToLower(), new PublishReleaseModel - { - Content = config.ConfigObject.Content, - FormatLabelCode = config.ConfigObject.FormatLabelCode, - Encryption = config.ConfigObject.Encryption - }); + Content = config.ConfigObject.Content, + FormatLabelCode = config.ConfigObject.FormatLabelCode, + Encryption = config.ConfigObject.Encryption }); - } - }); + }); + } + }); - return "success"; - } + return "success"; + } - public async Task> GetConfigObjectsAsync(string environmentName, - string clusterName, string appId, List? configObjects) + public async Task> GetConfigObjectsAsync(string environmentName, + string clusterName, string appId, List? configObjects) + { + var resultDic = new Dictionary(); + + var envs = await _pmClient.EnvironmentService.GetListAsync(); + var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist"); + var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id); + var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist"); + var apps = await _pmClient.AppService.GetListAsync(); + var app = apps.FirstOrDefault(apps => apps.Identity.ToLower() == appId.ToLower()) ?? throw new UserFriendlyException("AppId does not exist"); + + Expression> configObjectFilter = configObject => + configObject.AppConfigObject.EnvironmentClusterId == cluster.Id && + configObject.AppConfigObject.AppId == app.Id && + ((configObjects == null || configObjects.Count == 0) || configObjects.Contains(configObject.Name)); + var configObjectList = await _configObjectRepository.GetListAsync(configObjectFilter); + if (configObjects == null || configObjects.Count == 0) { - var resultDic = new Dictionary(); - - var envs = await _pmClient.EnvironmentService.GetListAsync(); - var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist"); - var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id); - var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist"); - var apps = await _pmClient.AppService.GetListAsync(); - var app = apps.FirstOrDefault(apps => apps.Identity.ToLower() == appId.ToLower()) ?? throw new UserFriendlyException("AppId does not exist"); - - Expression> configObjectFilter = configObject => - configObject.AppConfigObject.EnvironmentClusterId == cluster.Id && - configObject.AppConfigObject.AppId == app.Id && - ((configObjects == null || configObjects.Count == 0) || configObjects.Contains(configObject.Name)); - var configObjectList = await _configObjectRepository.GetListAsync(configObjectFilter); - if (configObjects == null || configObjects.Count == 0) - { - var configObjectPublicList = await _configObjectRepository.GetListAsync(configObject => configObject.PublicConfigObject.EnvironmentClusterId == cluster.Id); - configObjectList = configObjectList.Union(configObjectPublicList); - } + var configObjectPublicList = await _configObjectRepository.GetListAsync(configObject => configObject.PublicConfigObject.EnvironmentClusterId == cluster.Id); + configObjectList = configObjectList.Union(configObjectPublicList); + } - foreach (var configObject in configObjectList) + foreach (var configObject in configObjectList) + { + var key = $"{configObject.Name}".ToLower();//{environmentName}-{clusterName}-{appId}- + if (resultDic.ContainsKey(key)) continue; + resultDic.Add(key, new PublishReleaseModel() { - var key = $"{configObject.Name}".ToLower();//{environmentName}-{clusterName}-{appId}- - if (resultDic.ContainsKey(key)) continue; - resultDic.Add(key, new PublishReleaseModel() - { - Encryption = configObject.Encryption, - FormatLabelCode = configObject.FormatLabelCode, - Content = configObject.Content, - }); - } - - return resultDic; + Encryption = configObject.Encryption, + FormatLabelCode = configObject.FormatLabelCode, + Content = configObject.Content, + }); } + + return resultDic; } } diff --git a/src/Services/Masa.Dcc.Service/Domain/Label/Aggregates/Label.cs b/src/Services/Masa.Dcc.Service/Domain/Label/Aggregates/Label.cs deleted file mode 100644 index 63ef3167..00000000 --- a/src/Services/Masa.Dcc.Service/Domain/Label/Aggregates/Label.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Domain.Label.Aggregates -{ - [Table("Labels")] - [Index(nameof(TypeCode), nameof(IsDeleted), Name = "IX_TypeCode")] - public class Label : FullAggregateRoot - { - [Comment("Code")] - [Required(ErrorMessage = "Label code is required")] - [StringLength(100, MinimumLength = 2, ErrorMessage = "Label code length range is [2-100]")] - public string Code { get; set; } - - [Comment("Name")] - [Required(ErrorMessage = "Label name is required")] - [StringLength(100, MinimumLength = 2, ErrorMessage = "Label name length range is [2-100]")] - public string Name { get; private set; } - - [Comment("TypeCode")] - [Required(ErrorMessage = "TypeCode is required")] - [StringLength(255, MinimumLength = 0, ErrorMessage = "TypeCode length range is [0-255]")] - public string TypeCode { get; private set; } - - [Comment("TypeName")] - [Required(ErrorMessage = "TypeName is required")] - [StringLength(255, MinimumLength = 0, ErrorMessage = "TypeName length range is [0-255]")] - public string TypeName { get; private set; } - - [Comment("Description")] - [Required(ErrorMessage = "Description is required")] - [StringLength(255, MinimumLength = 0, ErrorMessage = "Description length range is [0-255]")] - public string Description { get; private set; } - - public Label(string code, string name, string typeCode, string typeName, string description = "") - { - Code = code; - Name = name; - TypeCode = typeCode; - TypeName = typeName; - Description = description; - } - - public Label(string code, string name, string typeCode, string typeName, Guid creator, DateTime creationTime, string description = "") - { - Code = code; - Name = name; - TypeCode = typeCode; - TypeName = typeName; - Creator = creator; - CreationTime = creationTime; - Description = description; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Domain/Label/Services/LabelDomainService.cs b/src/Services/Masa.Dcc.Service/Domain/Label/Services/LabelDomainService.cs index 3fd3d569..4e848c7a 100644 --- a/src/Services/Masa.Dcc.Service/Domain/Label/Services/LabelDomainService.cs +++ b/src/Services/Masa.Dcc.Service/Domain/Label/Services/LabelDomainService.cs @@ -1,85 +1,84 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Domain.Label.Services +namespace Masa.Dcc.Service.Admin.Domain.Label.Services; + +public class LabelDomainService : DomainService { - public class LabelDomainService : DomainService + private readonly ILabelRepository _labelRepository; + private readonly IDistributedCacheClient _distributedCacheClient; + private readonly II18n _i18n; + + public LabelDomainService(IDomainEventBus eventBus, + ILabelRepository labelRepository, + IDistributedCacheClient distributedCacheClient, + II18n i18N) : base(eventBus) { - private readonly ILabelRepository _labelRepository; - private readonly IDistributedCacheClient _distributedCacheClient; - private readonly II18n _i18n; + _labelRepository = labelRepository; + _distributedCacheClient = distributedCacheClient; + _i18n = i18N; + } - public LabelDomainService(IDomainEventBus eventBus, - ILabelRepository labelRepository, - IDistributedCacheClient distributedCacheClient, - II18n i18N) : base(eventBus) + public async Task AddLabelAsync(UpdateLabelDto labelDto) + { + if (!labelDto.LabelValues.Any()) { - _labelRepository = labelRepository; - _distributedCacheClient = distributedCacheClient; - _i18n = i18N; + throw new UserFriendlyException("Label values can not be null"); } - - public async Task AddLabelAsync(UpdateLabelDto labelDto) + else { - if (!labelDto.LabelValues.Any()) + var label = await _labelRepository.FindAsync(x => x.TypeCode == labelDto.TypeCode); + if (label is not null) { - throw new UserFriendlyException("Label values can not be null"); + throw new UserFriendlyException(_i18n.T("Duplicate label type code")); } - else - { - var label = await _labelRepository.FindAsync(x => x.TypeCode == labelDto.TypeCode); - if (label is not null) - { - throw new UserFriendlyException(_i18n.T("Duplicate label type code")); - } - - List labels = new(); - foreach (var item in labelDto.LabelValues) - { - var labelEntity = new Aggregates.Label(item.Code, - item.Name, - labelDto.TypeCode, - labelDto.TypeName, - labelDto.Description); - labels.Add(labelEntity); - } - await _labelRepository.AddRangeAsync(labels); - await _distributedCacheClient.SetAsync(labelDto.TypeCode, labels.Adapt>()); + List labels = new(); + foreach (var item in labelDto.LabelValues) + { + var labelEntity = new Dcc.Infrastructure.Domain.Label.Aggregates.Label(item.Code, + item.Name, + labelDto.TypeCode, + labelDto.TypeName, + labelDto.Description); + labels.Add(labelEntity); } + + await _labelRepository.AddRangeAsync(labels); + await _distributedCacheClient.SetAsync(labelDto.TypeCode, labels.Adapt>()); } + } - public async Task UpdateLabelAsync(UpdateLabelDto labelDto) + public async Task UpdateLabelAsync(UpdateLabelDto labelDto) + { + var labelEntities = await _labelRepository.GetListAsync(l => l.TypeCode.Equals(labelDto.TypeCode)); + if (labelEntities.Any()) { - var labelEntities = await _labelRepository.GetListAsync(l => l.TypeCode.Equals(labelDto.TypeCode)); - if (labelEntities.Any()) - { - await _labelRepository.RemoveRangeAsync(labelEntities); - - List labels = new(); - var labelEntity = labelEntities.First(); - foreach (var item in labelDto.LabelValues) - { - labels.Add(new Aggregates.Label(item.Code, - item.Name, - labelDto.TypeCode, - labelDto.TypeName, - labelEntity.Creator, - labelEntity.CreationTime, - labelDto.Description)); - } + await _labelRepository.RemoveRangeAsync(labelEntities); - await _labelRepository.AddRangeAsync(labels); - await _distributedCacheClient.SetAsync(labelDto.TypeCode, labels.Adapt>()); + List labels = new(); + var labelEntity = labelEntities.First(); + foreach (var item in labelDto.LabelValues) + { + labels.Add(new Dcc.Infrastructure.Domain.Label.Aggregates.Label(item.Code, + item.Name, + labelDto.TypeCode, + labelDto.TypeName, + labelEntity.Creator, + labelEntity.CreationTime, + labelDto.Description)); } + + await _labelRepository.AddRangeAsync(labels); + await _distributedCacheClient.SetAsync(labelDto.TypeCode, labels.Adapt>()); } + } - public async Task RemoveLaeblAsync(string typeCode) - { - var labels = await _labelRepository.GetListAsync(label => label.TypeCode == typeCode) ?? throw new UserFriendlyException("Label does not exist"); - await _labelRepository.RemoveRangeAsync(labels); + public async Task RemoveLaeblAsync(string typeCode) + { + var labels = await _labelRepository.GetListAsync(label => label.TypeCode == typeCode) ?? throw new UserFriendlyException("Label does not exist"); + await _labelRepository.RemoveRangeAsync(labels); - await _distributedCacheClient.RemoveAsync>(typeCode); - } + await _distributedCacheClient.RemoveAsync>(typeCode); } } diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs deleted file mode 100644 index af2be3e5..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppConfigEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class AppConfigEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs deleted file mode 100644 index f9eef7cf..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppPinEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class AppPinEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs deleted file mode 100644 index 93a789a3..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/AppSecretEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class AppSecretEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs deleted file mode 100644 index e5b7fbab..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class ConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs deleted file mode 100644 index 3caba81f..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/ConfigObjectReleaseEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class ConfigObjectReleaseEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs deleted file mode 100644 index d474a401..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class PublicConfigEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs deleted file mode 100644 index bc75ea15..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/App/PublicConfigObjectEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.App -{ - public class PublicConfigObjectEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs b/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs deleted file mode 100644 index 3b9fe4e2..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/EntityConfigurations/Label/LabelEntityTypeConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.EntityConfigurations.Label -{ - public class LabelEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs deleted file mode 100644 index 9e3221c8..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.App -{ - public class AppConfigObjectRepository : Repository, IAppConfigObjectRepository - { - public AppConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - - public async Task> GetListByEnvClusterIdAsync(int envClusterId, int appId, - bool getLatestRelease) - { - var configData = await Context.Set() - .Where(appConfigObject => appConfigObject.EnvironmentClusterId == envClusterId && appConfigObject.AppId == appId) - .Include(appConfigObject => appConfigObject.ConfigObject) - .AsNoTracking().ToListAsync(); - - if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); - - return configData; - } - - public async Task> GetAppLatestReleaseConfigAsync(IEnumerable appIds, int? envClusterId) - { - List<(int AppId, ConfigObjectRelease Release)> result = new(); - if (appIds?.Any() != true) - { - return result; - } - Expression> condition = appConfig => appIds.Contains(appConfig.AppId); - if (envClusterId.HasValue) - { - condition.And(x => x.EnvironmentClusterId == envClusterId.Value); - } - var qConfigs = Context.Set() - .Where(condition) - .Select(b => new { b.ConfigObjectId, b.AppId }); - - var qRelease = from biz in qConfigs - join r in Context.Set() on biz.ConfigObjectId equals r.ConfigObjectId into rNullable - from release in rNullable.DefaultIfEmpty() - select new { biz.AppId, release }; - - var qResult = await qRelease.OrderByDescending(x => x.release.CreationTime).AsNoTracking().ToListAsync(); - foreach (var appId in appIds) - { - var app = qResult.FirstOrDefault(x => x.AppId == appId); - if (app != null && app.release != null) - { - result.Add((appId, app.release)); - } - } - return result; - } - - public async Task> GetListByAppIdAsync(int appId) - { - var configData = await Context.Set() - .Include(appConfigObject => appConfigObject.ConfigObject) - .Where(appConfigObject => appConfigObject.AppId == appId) - .ToListAsync(); - - return configData; - } - - - public async Task GetbyConfigObjectIdAsync(int configObjectId) - { - var result = await Context.Set() - .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); - - return result ?? new(0, 0); - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppPinRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppPinRepository.cs deleted file mode 100644 index e16f654d..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppPinRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.App -{ - public class AppPinRepository : Repository, IAppPinRepository - { - public AppPinRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { } - - public async Task> GetListAsync(List appIds) - { - var result = await Context.Set() - .IgnoreQueryFilters() - .Where(app => appIds.Contains(app.AppId)) - .GroupBy(app => app.AppId) - .Select(app => app.OrderByDescending(a => a.Id).First()) - .ToListAsync(); - - return result; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs deleted file mode 100644 index 3d5eb88d..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.App -{ - public class BizConfigObjectRepository : Repository, IBizConfigObjectRepository - { - public BizConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - - public async Task> GetListByEnvClusterIdAsync(int envClusterId, int bizConfigId, - bool getLatestRelease) - { - var configData = await Context.Set() - .Where(bizConfigObject => bizConfigObject.EnvironmentClusterId == envClusterId && - bizConfigObject.BizConfigId == bizConfigId) - .Include(bizConfigObject => bizConfigObject.ConfigObject) - .ToListAsync(); - - if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); - - return configData; - } - - public async Task> GetListByBizConfigIdAsync(int bizConfigId) - { - var bizConfigObjects = await Context.Set() - .Include(bizConfigObject => bizConfigObject.ConfigObject) - .Where(bizConfigObject => bizConfigObject.BizConfigId == bizConfigId) - .ToListAsync(); - - return bizConfigObjects; - } - - public async Task> - GetProjectLatestReleaseConfigAsync( - List projects, int? envClusterId = null) - { - - List<(ConfigObjectRelease Release, int ProjectId)> result = new(); - if (projects?.Any() != true) - { - return result; - } - - var identities = projects.Select(x => (x.Identity + DccConst.BizConfigSuffix).ToLower()); - //var bizConfigs = await qBizConfigs.ToListAsync(); - - //var qReleases = Context.Set().GroupBy(r => r.ConfigObjectId) - // .Select(x => x.OrderByDescending(x => x.CreationTime).FirstOrDefault()); - ////select new { release = g.OrderByDescending(x => x.CreationTime).FirstOrDefault(), biz.BizConfig } - //; - //var test = await qReleases.ToListAsync(); - //var q = from biz in qBizConfigs - // join r in qReleases on biz.ConfigObjectId equals r.ConfigObjectId into rNullable - // from release in rNullable.DefaultIfEmpty() - // // where identities.Contains(biz.BizConfig.Identity) - // select new { biz.BizConfig.Identity }; - // TODO Group by is not support to join,it support in EFCore 7.0 https://github.com/dotnet/efcore/issues/24106 - - Expression> condition = x => identities.Contains(x.BizConfig.Identity); - if (envClusterId.HasValue) - { - condition.And(x => x.EnvironmentClusterId == envClusterId.Value); - } - var qConfigs = Context.Set() - .Include(x => x.BizConfig) - .Where(condition) - .Select(b => new { b.BizConfig.Identity, b.ConfigObjectId }); - - var qReleases = from biz in qConfigs - join r in Context.Set() on biz.ConfigObjectId equals r.ConfigObjectId into rNullable - from release in rNullable.DefaultIfEmpty() - select new { biz.Identity, release }; - - var qResult = await qReleases.OrderByDescending(x => x.release.CreationTime).AsNoTracking().ToListAsync(); - - foreach (var project in projects) - { - var m = qResult.FirstOrDefault(x => string.Equals(x.Identity, - project.Identity + DccConst.BizConfigSuffix, StringComparison.InvariantCultureIgnoreCase)); - if (m != null && m.release != null) - { - result.Add((m.release, project.Id)); - } - } - - return result; - } - - public async Task GetByConfigObjectIdAsync(int configObjectId) - { - var result = await Context.Set() - .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); - - return result ?? new(0, 0); - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigRepository.cs deleted file mode 100644 index 9fe5bd50..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.App -{ - public class BizConfigRepository : Repository, IBizConfigRepository - { - public BizConfigRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectReleaseRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectReleaseRepository.cs deleted file mode 100644 index b322e0e5..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectReleaseRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.App -{ - public class ConfigObjectReleaseRepository : Repository, IConfigObjectReleaseRepository - { - public ConfigObjectReleaseRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectRepository.cs deleted file mode 100644 index 53efbe38..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/ConfigObjectRepository.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories -{ - public class ConfigObjectRepository : Repository, IConfigObjectRepository - { - public ConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - - public async Task GetConfigObjectWithReleaseHistoriesAsync(int id) - { - var configObject = await Context.Set() - .Where(configObject => configObject.Id == id) - .Include(configObject => configObject.ConfigObjectRelease) - .FirstOrDefaultAsync(); - - return configObject ?? throw new Exception("Config object does not exist"); - } - - public async Task> GetRelationConfigObjectWithReleaseHistoriesAsync(int id) - { - var configObjects = await Context.Set() - .Where(configObject => configObject.RelationConfigObjectId == id) - .Include(configObject => configObject.ConfigObjectRelease) - .ToListAsync(); - - return configObjects; - } - - public async Task> GetNewestConfigObjectReleaseWithAppInfo() - { - var configObjectReleaseQuery = Context.Set() - .Join( - Context.Set(), - configObject => configObject.Id, - configObjectRelease => configObjectRelease.ConfigObjectId, - (configObject, configObjectRelease) => new - { - ConfigObject = configObject, - ConfigObjectReleaseId = configObjectRelease.Id, - } - ); - - var result = await configObjectReleaseQuery - .Join( - Context.Set(), - configObjectGroup => configObjectGroup.ConfigObject.Id, - appConfigObject => appConfigObject.ConfigObjectId, - (configObjectGroup, appConfigObject) => new - { - configObjectGroup.ConfigObject, - configObjectGroup.ConfigObjectReleaseId, - configObjectGroup.ConfigObject.Type, - appConfigObject.AppId, - appConfigObject.EnvironmentClusterId - } - ) - .GroupBy(config => config.ConfigObject.Id) - .Select(config => config.OrderByDescending(c => c.ConfigObjectReleaseId).First()) - .ToListAsync(); - - var publicResult = await configObjectReleaseQuery - .Join( - Context.Set(), - configObjectGroup => configObjectGroup.ConfigObject.Id, - publicConfigObject => publicConfigObject.ConfigObjectId, - (configObjectGroup, publicConfigObject) => new - { - configObjectGroup.ConfigObject, - configObjectGroup.ConfigObjectReleaseId, - configObjectGroup.ConfigObject.Type, - publicConfigObject.PublicConfigId, - publicConfigObject.EnvironmentClusterId - } - ) - .GroupBy(config => config.ConfigObject.Id) - .Select(config => config.OrderByDescending(c => c.ConfigObjectReleaseId).First()) - .ToListAsync(); - - return result - .Select(config => - new ValueTuple(config.ConfigObject, config.AppId, config.EnvironmentClusterId)) - .Union(publicResult.Select(config => - new ValueTuple(config.ConfigObject, config.PublicConfigId, config.EnvironmentClusterId))) - .ToList(); - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigObjectRepository.cs deleted file mode 100644 index c371c79d..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigObjectRepository.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories -{ - public class PublicConfigObjectRepository : Repository, IPublicConfigObjectRepository - { - public PublicConfigObjectRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - - public async Task> GetListByEnvClusterIdAsync(int? envClusterId, int publicConfigId, - bool getLatestRelease) - { - Expression> condition = p => p.PublicConfigId == publicConfigId; - if (envClusterId.HasValue && envClusterId != 0) - condition = condition.And(p => p.EnvironmentClusterId == envClusterId); - - var configData = await Context.Set() - .Where(condition) - .Include(publicConfigObject => publicConfigObject.ConfigObject) - .ToListAsync(); - - if (getLatestRelease) await Context.GetLatestReleaseOfConfigData(configData); - - return configData; - } - - public async Task GetByConfigObjectIdAsync(int configObjectId) - { - var result = await Context.Set() - .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); - - return result ?? new(0, 0); - } - - public async Task> GetListByPublicConfigIdAsync(int publicConfigId) - { - var configData = await Context.Set() - .Include(pubConfig => pubConfig.ConfigObject) - .Where(pubConfig => pubConfig.PublicConfigId == publicConfigId) - .ToListAsync(); - - return configData; - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigRepository.cs deleted file mode 100644 index ef371f5a..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/PublicConfigRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Infrastructure.Repositories -{ - public class PublicConfigRepository : Repository, IPublicConfigRepository - { - public PublicConfigRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - } -} \ No newline at end of file diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/Label/LabelRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/Label/LabelRepository.cs deleted file mode 100644 index 370b57ca..00000000 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/Label/LabelRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Dcc.Service.Admin.Infrastructure.Repositories.Label -{ - public class LabelRepository : Repository, ILabelRepository - { - public LabelRepository(DccDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork) - { - } - } -} diff --git a/src/Services/Masa.Dcc.Service/Masa.Dcc.Service.Admin.csproj b/src/Services/Masa.Dcc.Service/Masa.Dcc.Service.Admin.csproj index bf65fd0d..f8b8cf19 100644 --- a/src/Services/Masa.Dcc.Service/Masa.Dcc.Service.Admin.csproj +++ b/src/Services/Masa.Dcc.Service/Masa.Dcc.Service.Admin.csproj @@ -9,13 +9,6 @@ ..\..\.. - - - - - - - @@ -23,7 +16,6 @@ - @@ -31,11 +23,9 @@ - - @@ -46,22 +36,16 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + - - - diff --git a/src/Services/Masa.Dcc.Service/Program.cs b/src/Services/Masa.Dcc.Service/Program.cs index f17fb9af..15b53f19 100644 --- a/src/Services/Masa.Dcc.Service/Program.cs +++ b/src/Services/Masa.Dcc.Service/Program.cs @@ -8,6 +8,9 @@ await builder.Services.AddMasaStackConfigAsync(project: MasaStackProject.DCC, app: MasaStackApp.Service); var masaStackConfig = builder.Services.GetMasaStackConfig(); +var connStr = masaStackConfig.GetValue(MasaStackConfigConstant.CONNECTIONSTRING); +var dbModel = JsonSerializer.Deserialize(connStr)!; +bool isPgsql = string.Equals(dbModel.DbType, "postgresql", StringComparison.CurrentCultureIgnoreCase); if (!builder.Environment.IsDevelopment()) { @@ -103,14 +106,20 @@ options.RegisterValidatorsFromAssemblyContaining(); }) .AddDomainEventBus(options => - { - var connStr = masaStackConfig.GetConnectionString(MasaStackProject.DCC.Name); - options.UseIntegrationEventBus(options => options.UseDapr() - .UseEventLog()) - .UseEventBus() - .UseUoW(dbOptions => dbOptions.UseSqlServer(connStr) - .UseFilter()) - .UseRepository(); + { + var connStr = masaStackConfig.GetConnectionString(MasaStackProject.DCC.Name); + if (isPgsql) + DccDbContext.RegistAssembly(Assembly.Load("Masa.Dcc.Infrastructure.EFCore.PostgreSql")); + else + DccDbContext.RegistAssembly(Assembly.Load("Masa.Dcc.Infrastructure.EFCore.SqlServer")); + + options.UseIntegrationEventBus(options => + options.UseDapr() + .UseEventBus()) + .UseUoW(dbOptions => + (isPgsql ? dbOptions.UsePgsql(connStr, options => options.MigrationsAssembly("Masa.Dcc.Infrastructure.EFCore.PostgreSql")) : + dbOptions.UseSqlServer(connStr, options => options.MigrationsAssembly("Masa.Dcc.Infrastructure.EFCore.SqlServer"))).UseFilter()) + .UseRepository(); }); builder.Services.AddI18n(Path.Combine("Assets", "I18n")); @@ -118,10 +127,7 @@ //seed data await builder.SeedDataAsync(); -var app = builder.AddServices(options => -{ - options.DisableAutoMapRoute = true; // todo :remove it before v1.0 -}); +var app = builder.Services.AddServices(builder, new Assembly[] { typeof(IAppConfigObjectRepository).Assembly, typeof(Masa.Dcc.Service.Admin.Services.AppService).Assembly }); if (app.Environment.IsDevelopment()) diff --git a/src/Services/Masa.Dcc.Service/Services/AppService.cs b/src/Services/Masa.Dcc.Service/Services/AppService.cs index 45d3ff34..04891922 100644 --- a/src/Services/Masa.Dcc.Service/Services/AppService.cs +++ b/src/Services/Masa.Dcc.Service/Services/AppService.cs @@ -7,6 +7,7 @@ public class AppService : ServiceBase { public AppService() { + RouteOptions.DisableAutoMapRoute = true; App.MapGet("api/v1/app/{id}", GetAsync); App.MapPost("api/v1/projects/app", GetListByProjectIdsAsync); App.MapGet("api/v1/appWithEnvCluster/{id}", GetWithEnvironmentClusterAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/BizConfigService.cs b/src/Services/Masa.Dcc.Service/Services/BizConfigService.cs index ebfc2c3b..377756d0 100644 --- a/src/Services/Masa.Dcc.Service/Services/BizConfigService.cs +++ b/src/Services/Masa.Dcc.Service/Services/BizConfigService.cs @@ -1,50 +1,49 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -namespace Masa.Dcc.Service.Admin.Services +namespace Masa.Dcc.Service.Admin.Services; + +public class BizConfigService : ServiceBase { - public class BizConfigService : ServiceBase + public BizConfigService() + { + RouteOptions.DisableAutoMapRoute = true; + App.MapPost("api/v1/bizConfig", AddAsync); + App.MapPut("api/v1/bizConfig", UpdateAsync); + App.MapGet("api/v1/bizConfig/{identity}", GetAsync); + App.MapPost("api/v1/bizConfig/latestReleaseConfig", GetLatestReleaseConfigByProjectAsync); + } + + public async Task> GetLatestReleaseConfigByProjectAsync(IEventBus eventBus, + IAuthClient authClient, + LatestReleaseConfigRequestDto request) + { + var query = new ProjectLatestReleaseQuery(request.Items, request.EnvClusterId); + await eventBus.PublishAsync(query); + return await authClient.FillUserNameAsync(query.Result); + } + + public async Task AddAsync(IEventBus eventBus, AddObjectConfigDto dto) + { + var command = new AddBizConfigCommand(dto); + await eventBus.PublishAsync(command); + + return command.BizConfigDto; + } + + public async Task UpdateAsync(IEventBus eventBus, UpdateObjectConfigDto dto) + { + var command = new UpdateBizConfigCommand(dto); + await eventBus.PublishAsync(command); + + return command.BizConfigDto; + } + + public async Task GetAsync(IEventBus eventBus, string identity) { + var query = new BizConfigsQuery(identity); + await eventBus.PublishAsync(query); - public BizConfigService() - { - App.MapPost("api/v1/bizConfig", AddAsync); - App.MapPut("api/v1/bizConfig", UpdateAsync); - App.MapGet("api/v1/bizConfig/{identity}", GetAsync); - App.MapPost("api/v1/bizConfig/latestReleaseConfig", GetLatestReleaseConfigByProjectAsync); - } - - public async Task> GetLatestReleaseConfigByProjectAsync(IEventBus eventBus, - IAuthClient authClient, - LatestReleaseConfigRequestDto request) - { - var query = new ProjectLatestReleaseQuery(request.Items, request.EnvClusterId); - await eventBus.PublishAsync(query); - return await authClient.FillUserNameAsync(query.Result); - } - - public async Task AddAsync(IEventBus eventBus, AddObjectConfigDto dto) - { - var command = new AddBizConfigCommand(dto); - await eventBus.PublishAsync(command); - - return command.BizConfigDto; - } - - public async Task UpdateAsync(IEventBus eventBus, UpdateObjectConfigDto dto) - { - var command = new UpdateBizConfigCommand(dto); - await eventBus.PublishAsync(command); - - return command.BizConfigDto; - } - - public async Task GetAsync(IEventBus eventBus, string identity) - { - var query = new BizConfigsQuery(identity); - await eventBus.PublishAsync(query); - - return query.Result; - } + return query.Result; } } diff --git a/src/Services/Masa.Dcc.Service/Services/ClusterService.cs b/src/Services/Masa.Dcc.Service/Services/ClusterService.cs index 8189c72f..25ddac80 100644 --- a/src/Services/Masa.Dcc.Service/Services/ClusterService.cs +++ b/src/Services/Masa.Dcc.Service/Services/ClusterService.cs @@ -7,6 +7,7 @@ public class ClusterService : ServiceBase { public ClusterService(IPmClient pmClient) { + RouteOptions.DisableAutoMapRoute = true; App.MapGet("api/v1/cluster", GetListAsync); App.MapGet("api/v1/cluster/{Id}", GetAsync); App.MapGet("api/v1/envClusters", GetEnvironmentClustersAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/ConfigObjectService.cs b/src/Services/Masa.Dcc.Service/Services/ConfigObjectService.cs index 4d8aa265..a518e5f3 100644 --- a/src/Services/Masa.Dcc.Service/Services/ConfigObjectService.cs +++ b/src/Services/Masa.Dcc.Service/Services/ConfigObjectService.cs @@ -7,6 +7,7 @@ public class ConfigObjectService : ServiceBase { public ConfigObjectService() { + RouteOptions.DisableAutoMapRoute = true; App.MapPost("api/v1/configObject", AddAsync); App.MapDelete("api/v1/configObject", RemoveAsync); App.MapGet("api/v1/configObjects/{envClusterId}/{objectId}/{type}/{getLatestRelease}", GetListAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/EnvironmentService.cs b/src/Services/Masa.Dcc.Service/Services/EnvironmentService.cs index 556ed105..07f1289d 100644 --- a/src/Services/Masa.Dcc.Service/Services/EnvironmentService.cs +++ b/src/Services/Masa.Dcc.Service/Services/EnvironmentService.cs @@ -7,6 +7,7 @@ public class EnvironmentService : ServiceBase { public EnvironmentService(IPmClient pmClient) { + RouteOptions.DisableAutoMapRoute = true; App.MapGet("api/v1/env", GetListAsync); App.MapGet("api/v1/env/{Id}", GetAsync); } diff --git a/src/Services/Masa.Dcc.Service/Services/LabelService.cs b/src/Services/Masa.Dcc.Service/Services/LabelService.cs index e9d3130e..607ab6f2 100644 --- a/src/Services/Masa.Dcc.Service/Services/LabelService.cs +++ b/src/Services/Masa.Dcc.Service/Services/LabelService.cs @@ -7,6 +7,7 @@ public class LabelService : ServiceBase { public LabelService() { + RouteOptions.DisableAutoMapRoute = true; App.MapGet("api/v1/labels", GetListAsync); App.MapGet("api/v1/{typeCode}/labels", GetLabelsByTypeCodeAsync); App.MapPost("api/v1/labels", AddAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs b/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs index f065b08c..87c17bee 100644 --- a/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs +++ b/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs @@ -7,6 +7,7 @@ public class OpenApiService : ServiceBase { public OpenApiService() { + RouteOptions.DisableAutoMapRoute = true; App.MapPut("open-api/releasing/{environment}/{cluster}/{appId}/{configObject}", UpdateConfigObjectAsync); App.MapPost("open-api/releasing/{environment}/{cluster}/{appId}/{isEncryption}", AddConfigObjectAsync); App.MapPost("open-api/releasing/get/{environment}/{cluster}/{appId}", GetConfigObjectsAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/ProjectService.cs b/src/Services/Masa.Dcc.Service/Services/ProjectService.cs index ea6d4438..29d4eb4f 100644 --- a/src/Services/Masa.Dcc.Service/Services/ProjectService.cs +++ b/src/Services/Masa.Dcc.Service/Services/ProjectService.cs @@ -7,6 +7,7 @@ public class ProjectService : ServiceBase { public ProjectService(IPmClient pmClient) { + RouteOptions.DisableAutoMapRoute = true; App.MapGet("api/v1/projectwithapps/{envName}", GetProjectListAsync); App.MapGet("api/v1/project/{id}", GetAsync); App.MapGet("api/v1/{envClusterId}/project", GetListByEnvironmentClusterIdAsync); diff --git a/src/Services/Masa.Dcc.Service/Services/PublicConfigService.cs b/src/Services/Masa.Dcc.Service/Services/PublicConfigService.cs index 70176c8c..3ba5348d 100644 --- a/src/Services/Masa.Dcc.Service/Services/PublicConfigService.cs +++ b/src/Services/Masa.Dcc.Service/Services/PublicConfigService.cs @@ -7,6 +7,7 @@ public class PublicConfigService : ServiceBase { public PublicConfigService() { + RouteOptions.DisableAutoMapRoute = true; App.MapPost("api/v1/publicConfig", AddAsync); App.MapPut("api/v1/publicConfig", UpdateAsync); App.MapDelete("api/v1/publicConfig/{Id}", RemoveAsync); diff --git a/src/Services/Masa.Dcc.Service/_Imports.cs b/src/Services/Masa.Dcc.Service/_Imports.cs index 718e02f8..9bf2faff 100644 --- a/src/Services/Masa.Dcc.Service/_Imports.cs +++ b/src/Services/Masa.Dcc.Service/_Imports.cs @@ -1,8 +1,6 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -global using System.ComponentModel.DataAnnotations; -global using System.ComponentModel.DataAnnotations.Schema; global using System.Linq.Expressions; global using System.Reflection; global using System.Text.Encodings.Web; @@ -17,7 +15,6 @@ global using Masa.BuildingBlocks.Caching; global using Masa.BuildingBlocks.Configuration; global using Masa.BuildingBlocks.Data.UoW; -global using Masa.BuildingBlocks.Ddd.Domain.Entities.Full; global using Masa.BuildingBlocks.Ddd.Domain.Events; global using Masa.BuildingBlocks.Ddd.Domain.Repositories; global using Masa.BuildingBlocks.Ddd.Domain.Services; @@ -30,38 +27,33 @@ global using Masa.BuildingBlocks.StackSdks.Auth.Contracts; global using Masa.BuildingBlocks.StackSdks.Config; global using Masa.BuildingBlocks.StackSdks.Config.Consts; +global using Masa.BuildingBlocks.StackSdks.Config.Models; global using Masa.BuildingBlocks.StackSdks.Dcc.Contracts.Model; global using Masa.BuildingBlocks.StackSdks.Middleware; global using Masa.BuildingBlocks.StackSdks.Pm; -global using Masa.BuildingBlocks.StackSdks.Pm.Enum; global using Masa.BuildingBlocks.StackSdks.Pm.Model; global using Masa.Contrib.Caching.Distributed.StackExchangeRedis; -global using Masa.Contrib.Ddd.Domain.Repository.EFCore; global using Masa.Contrib.Dispatcher.Events; -global using Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore; global using Masa.Contrib.StackSdks.Config; global using Masa.Contrib.StackSdks.Middleware; global using Masa.Contrib.StackSdks.Tsc; -global using Masa.Dcc.Contracts.Admin; global using Masa.Dcc.Contracts.Admin.App.Dtos; global using Masa.Dcc.Contracts.Admin.App.Enums; global using Masa.Dcc.Contracts.Admin.Label.Dtos; +global using Masa.Dcc.Infrastructure.Domain.App.Aggregates; +global using Masa.Dcc.Infrastructure.Domain.Label.Aggregates; +global using Masa.Dcc.Infrastructure.EFCore; +global using Masa.Dcc.Infrastructure.Repository.App; +global using Masa.Dcc.Infrastructure.Repository.Label; global using Masa.Dcc.Service.Admin.Application.App.Commands; global using Masa.Dcc.Service.Admin.Application.App.Queries; global using Masa.Dcc.Service.Admin.Application.Label.Commands; global using Masa.Dcc.Service.Admin.Application.Label.Queries; -global using Masa.Dcc.Service.Admin.Domain.App.Aggregates; -global using Masa.Dcc.Service.Admin.Domain.App.Repositories; global using Masa.Dcc.Service.Admin.Domain.App.Services; -global using Masa.Dcc.Service.Admin.Domain.Label.Aggregates; -global using Masa.Dcc.Service.Admin.Domain.Label.Repositories; global using Masa.Dcc.Service.Admin.Domain.Label.Services; global using Masa.Dcc.Service.Admin.Infrastructure; global using Masa.Dcc.Service.Admin.Infrastructure.Middleware; -global using Masa.Dcc.Service.Infrastructure; global using Masa.Utils.Security.Cryptography; global using Microsoft.AspNetCore.Authentication.JwtBearer; global using Microsoft.AspNetCore.Mvc; global using Microsoft.EntityFrameworkCore; -global using Microsoft.EntityFrameworkCore.Design; -global using Microsoft.EntityFrameworkCore.Metadata.Builders;