Skip to content

Commit

Permalink
feat: add domain layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng committed Dec 6, 2024
1 parent 61d6515 commit 3b007c6
Show file tree
Hide file tree
Showing 76 changed files with 684 additions and 634 deletions.
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[NotMapped]
public class App
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("AppConfigObjects")]
public class AppConfigObject : ConfigObjectBase
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

public class AppPin : FullAggregateRoot<int, Guid>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("AppSecrets")]
public class AppSecret : FullAggregateRoot<int, Guid>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("BizConfigs")]
public class BizConfig : FullAggregateRoot<int, Guid>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("BizConfigObjects")]
public class BizConfigObject : ConfigObjectBase
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("ConfigObjects")]
public class ConfigObject : FullAggregateRoot<int, Guid>
Expand All @@ -23,10 +23,10 @@ public class ConfigObject : FullAggregateRoot<int, Guid>
[Required]
public bool Encryption { get; private set; }

[Required]
[Required]
public string Content { get; private set; }

[Required]
[Required]
public string TempContent { get; private set; }

[Comment("Relation config object Id")]
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

public abstract class ConfigObjectBase : FullAggregateRoot<int, Guid>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// 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;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("ConfigObjectReleases")]
public class ConfigObjectRelease : FullAggregateRoot<int, Guid>
{
[Comment("Release type")]
[Comment("Release type")]
public ReleaseType Type { get; set; }

[Comment("Config object Id")]
Expand All @@ -21,22 +21,22 @@ public class ConfigObjectRelease : FullAggregateRoot<int, Guid>
public bool IsInvalid { get; set; }

[Comment("Version format is yyyyMMddHHmmss")]
[Required(ErrorMessage = "Version is required")]
[Required(ErrorMessage = "Version is required")]
public string Version { get; set; }

[Comment("Name")]
[Required(ErrorMessage = "Name is required", AllowEmptyStrings = true)]
[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)]
[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]")]
[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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("PublicConfigs")]
public class PublicConfig : FullAggregateRoot<int, Guid>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.App.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("PublicConfigObjects")]
public class PublicConfigObject : ConfigObjectBase
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Infrastructure.Domain.Label.Aggregates;
namespace Masa.Dcc.Infrastructure.Domain.Shared;

[Table("Labels")]
[Index(nameof(TypeCode), nameof(IsDeleted), Name = "IX_TypeCode")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Masa.BuildingBlocks.Ddd.Domain" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Ddd.Domain" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Pm" Version="$(MasaStackSdksPackageVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.7.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Contracts\Masa.Dcc.Contracts.Admin\Masa.Dcc.Contracts.Admin.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions Masa.Dcc.Infrastructure.Domain.Shared/_Imports.cs
Original file line number Diff line number Diff line change
@@ -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;
186 changes: 186 additions & 0 deletions Masa.Dcc.Infrastructure.Domain/App/CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// 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.App;

internal class CommandHandler
{
private readonly IPublicConfigRepository _publicConfigRepository;
private readonly IConfigObjectRepository _configObjectRepository;
private readonly IAppPinRepository _appPinRepository;
private readonly IBizConfigRepository _bizConfigRepository;
private readonly ConfigObjectDomainService _configObjectDomainService;
private readonly IUnitOfWork _unitOfWork;

public CommandHandler(
IPublicConfigRepository publicConfigRepository,
IConfigObjectRepository configObjectRepository,
IAppPinRepository appPinRepository,
IBizConfigRepository bizConfigRepository,
ConfigObjectDomainService configObjectDomainService,
IUnitOfWork unitOfWork)
{
_publicConfigRepository = publicConfigRepository;
_configObjectRepository = configObjectRepository;
_appPinRepository = appPinRepository;
_bizConfigRepository = bizConfigRepository;
_configObjectDomainService = configObjectDomainService;
_unitOfWork = unitOfWork;
}

#region PublicConfig

[EventHandler]
public async Task AddPublicConfigAsync(AddPublicConfigCommand command)
{
var publicConfig = command.AddPublicConfigDto;

var result = await _publicConfigRepository.AddAsync(
new PublicConfig(publicConfig.Name, publicConfig.Identity, publicConfig.Description));

command.PublicConfigDto = result.Adapt<PublicConfigDto>();
}

[EventHandler]
public async Task UpdatePublicConfigAsync(UpdatePublicConfigCommand command)
{
var publicConfig = command.UpdatePublicConfigDto;
var publicConfigEntity = await _publicConfigRepository.FindAsync(p => p.Id == publicConfig.Id)
?? throw new UserFriendlyException("Public config does not exist");

publicConfigEntity.Update(publicConfig.Name, publicConfig.Description);
await _publicConfigRepository.UpdateAsync(publicConfigEntity);
}

[EventHandler]
public async Task RemovePublicConfigAsync(RemovePublicConfigCommand command)
{
var publicConfigEntity = await _publicConfigRepository.FindAsync(p => p.Id == command.PublicConfigId)
?? throw new UserFriendlyException("Public config does not exist");

await _publicConfigRepository.RemoveAsync(publicConfigEntity);
}

#endregion

#region BizConfig

[EventHandler]
public async Task AddBizConfigAsync(AddBizConfigCommand command)
{
var bizConfig = command.AddBizConfigDto;

var result = await _bizConfigRepository.AddAsync(new BizConfig(bizConfig.Name, bizConfig.Identity));

await _unitOfWork.SaveChangesAsync();

command.BizConfigDto = result.Adapt<BizConfigDto>();
}

[EventHandler]
public async Task UpdateBizConfigAsync(UpdateBizConfigCommand command)
{
var bizConfig = command.UpdateBizConfigDto;
var bizConfigEntity = await _bizConfigRepository.FindAsync(p => p.Id == bizConfig.Id)
?? throw new UserFriendlyException("biz config does not exist");

bizConfigEntity.Update(bizConfig.Name);
var result = await _bizConfigRepository.UpdateAsync(bizConfigEntity);

command.BizConfigDto = result.Adapt<BizConfigDto>();
}

#endregion

#region ConfigObject

[EventHandler]
public async Task AddConfigObjectAsync(AddConfigObjectCommand command)
{
await _configObjectDomainService.AddConfigObjectAsync(command.ConfigObjectDtos);
}

[EventHandler]
public async Task RemoveConfigObjectAsync(RemoveConfigObjectCommand command)
{
await _configObjectDomainService.RemoveConfigObjectAsync(command.ConfigObjectDto);
}

[EventHandler]
public async Task UpdateConfigObjectContentAsync(UpdateConfigObjectContentCommand command)
{
await _configObjectDomainService.UpdateConfigObjectContentAsync(command.ConfigObjectContent);
}

[EventHandler]
public async Task RevokeConfigObjectAsync(RevokeConfigObjectCommand command)
{
var configObject = await _configObjectRepository.FindAsync(configObject => configObject.Id == command.ConfigObjectId);

if (configObject == null)
{
throw new UserFriendlyException("Config object does not exist");
}

configObject.Revoke();

await _configObjectRepository.UpdateAsync(configObject);
}

[EventHandler]
public async Task CloneConfigObjectAsync(CloneConfigObjectCommand command)
{
await _configObjectDomainService.CloneConfigObjectAsync(command.CloneConfigObject);
}

#endregion

#region Release

[EventHandler]
public async Task AddConfigObjectRelease(AddConfigObjectReleaseCommand command)
{
await _configObjectDomainService.AddConfigObjectReleaseAsync(command.ConfigObjectRelease);
}

[EventHandler]
public async Task RollbackConfigObjectReleaseAsync(RollbackConfigObjectReleaseCommand command)
{
await _configObjectDomainService.RollbackConfigObjectReleaseAsync(command.RollbackConfigObjectRelease);
}

#endregion

#region App

[EventHandler]
public async Task AddAppPinAsync(AddAppPinCommand command)
{
await _appPinRepository.AddAsync(new AppPin(command.AppId));
}

[EventHandler]
public async Task RemoveAppPinAsync(RemoveAppPinCommand command)
{
var appPin = await _appPinRepository.FindAsync(appPin => appPin.AppId == command.AppId);

if (appPin != null)
await _appPinRepository.RemoveAsync(appPin);
}

#endregion

[EventHandler]
public async Task UpdateConfigObjectAsync(UpdateConfigAndPublishCommand command)
{
await _configObjectDomainService.UpdateConfigObjectAsync(command.Environment, command.Cluster,
command.AppId, command.ConfigObject, command.Value);
}

[EventHandler]
public async Task InitConfigObjectAsync(InitConfigObjectCommand command)
{
await _configObjectDomainService.InitConfigObjectAsync(command.Environment, command.Cluster,
command.AppId, command.ConfigObjects, command.ConfigObjectType, command.IsEncryption);
}
}
Original file line number Diff line number Diff line change
@@ -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.Application.App.Commands
namespace Masa.Dcc.Infrastructure.Domain.Commands
{
public record AddAppPinCommand(int AppId) : Command
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Application.App.Commands
namespace Masa.Dcc.Infrastructure.Domain.Commands
{
[AllowedEvent]
public record AddBizConfigCommand(AddObjectConfigDto AddBizConfigDto) : Command
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Application.App.Commands
namespace Masa.Dcc.Infrastructure.Domain.Commands
{
public record AddConfigObjectCommand(List<AddConfigObjectDto> ConfigObjectDtos) : Command
{
Expand Down
Loading

0 comments on commit 3b007c6

Please sign in to comment.