Skip to content

Commit

Permalink
feat: add responsibility users for app (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyouzeng authored Jan 13, 2025
1 parent 316a84a commit 2b51637
Show file tree
Hide file tree
Showing 31 changed files with 1,494 additions and 137 deletions.
2 changes: 2 additions & 0 deletions src/Contracts/MASA.PM.Contracts.Admin/Dto/AddAppDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public string Name

[StringLength(255, ErrorMessage = "App description length must be less than 255")]
public string Description { get; set; } = "";

public List<Guid> ResponsibilityUsers { get; set; } = new();
}

public record EnvironmentClusterInfo
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/MASA.PM.Contracts.Admin/Dto/AppDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class AppDto : BaseDto

public string SwaggerUrl { get; set; } = "";

public List<Guid>? ResponsibilityUserIds { get; set; } = new();

public List<EnvironmentClusterDto> EnvironmentClusters { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ namespace MASA.PM.Infrastructure.Domain.Shared.Entities;
public class App : FullAggregateRoot<int, Guid>
{
[Comment("Name")]
[Required(ErrorMessage = "App name is required")]
[Required(ErrorMessage = "App name is required")]
[StringLength(100, MinimumLength = 2, ErrorMessage = "App name length range is [2-100]")]
public string Name { get; set; } = "";

/// <summary>
/// App Id
/// </summary>
[Comment("Identity")]
[Required(ErrorMessage = "App identity is required")]
[Required(ErrorMessage = "App identity is required")]
[StringLength(100, MinimumLength = 2, ErrorMessage = "App identity length range is [2-100]")]
public string Identity { get; set; } = "";

[Comment("Type")]
[Range(1, int.MaxValue, ErrorMessage = "App type is required")]
[Range(1, int.MaxValue, ErrorMessage = "App type is required")]
public AppTypes Type { get; set; }

[Comment("ServiceType")]
[Range(1, int.MaxValue, ErrorMessage = "App service type is required")]
[Range(1, int.MaxValue, ErrorMessage = "App service type is required")]
public ServiceTypes ServiceType { get; set; }

[Comment("Description")]
[Comment("Description")]
[StringLength(255, MinimumLength = 0, ErrorMessage = "Description length range is [0-255]")]
public string Description { get; set; } = "";

public List<AppResponsibilityUser>? ResponsibilityUsers { get; set; }

public void SetCreatorAndModifier(Guid userId)
{
Creator = userId;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.PM.Infrastructure.Domain.Shared.Entities;

[Table("AppResponsibilityUsers")]
public class AppResponsibilityUser : Entity<int>
{
public int AppId { get; set; }

public Guid UserId { get; set; }

public DateTime CreateTime { get; set; }

public App App { get; set; } = default!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ public async Task AddAppAsync(AddAppCommand command)
await _appRepository.IsExistedApp(
appModel.Name, appModel.Identity, envClusterProjects.Select(e => e.Id).ToList());

var app = await _appRepository.AddAsync(new Shared.Entities.App
var app = new Shared.Entities.App
{
Name = appModel.Name,
Type = appModel.Type,
ServiceType = appModel.ServiceType,
Identity = appModel.Identity,
Description = appModel.Description
});
};
app.ResponsibilityUsers = appModel.ResponsibilityUsers.Select(u => new AppResponsibilityUser
{
AppId = app.Id,
UserId = u
}).ToList();
app = await _appRepository.AddAsync(app);

List<EnvironmentClusterProjectApp> environmentClusterProjectApps = new();
foreach (var envClusterProject in envClusterProjects)
Expand Down Expand Up @@ -66,9 +72,8 @@ await _appRepository.IsExistedApp(
}

appEntity.Name = appModel.Name;
appEntity.Description = appModel.Description;

await _appRepository.UpdateAsync(appEntity);
appEntity.Description = appModel.Description;
await _appRepository.UpdateAsync(appEntity,appModel.ResponsibilityUsers);

var envClusterProjectApps = await _appRepository.GetEnvironmentClusterProjectAppsByAppId(appModel.Id);
await _appRepository.RemoveEnvironmentClusterProjectApps(envClusterProjectApps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public async Task GetAppAsync(AppQuery query)
CreationTime = app.CreationTime,
ModificationTime = app.ModificationTime,
Modifier = app.Modifier,
ResponsibilityUserIds = app.ResponsibilityUsers?.Select(m => m.UserId).ToList()
};

if (query.IsHaveEnvironmentClusterInfo)
Expand Down Expand Up @@ -66,6 +67,7 @@ public async Task GetAppAsync(AppByIdentityQuery query)
CreationTime = app.CreationTime,
ModificationTime = app.ModificationTime,
Modifier = app.Modifier,
ResponsibilityUserIds = app.ResponsibilityUsers?.Select(m => m.UserId).ToList()
};
}

Expand Down Expand Up @@ -119,6 +121,7 @@ public async Task GetAppListAsync(AppsQuery query)
CreationTime = appEnvironmentCluster.app.CreationTime,
ModificationTime = appEnvironmentCluster.app.ModificationTime,
Modifier = appEnvironmentCluster.app.Modifier,
ResponsibilityUserIds = appEnvironmentCluster.app.ResponsibilityUsers?.Select(r => r.UserId).ToList(),
EnvironmentClusters = appEnvironmentCluster.environmentClusters.Select(envCluster => new EnvironmentClusterDto
{
Id = envCluster.EnvironmentCluster.Id,
Expand All @@ -134,20 +137,21 @@ public async Task GetAppListAsync(AppsQuery query)
else
{
List<Shared.Entities.App> apps = await _appRepository.GetListAsync();
query.Result = apps.Select(app => new AppDto
{
Name = app.Name,
Description = app.Description,
Id = app.Id,
Identity = app.Identity,
Type = app.Type,
ServiceType = app.ServiceType,
Creator = app.Creator,
CreationTime = app.CreationTime,
ModificationTime = app.ModificationTime,
Modifier = app.Modifier
}).OrderByDescending(app => app.ModificationTime)
.ToList();
//query.Result = apps.Select(app => new AppDto
//{
// Name = app.Name,
// Description = app.Description,
// Id = app.Id,
// Identity = app.Identity,
// Type = app.Type,
// ServiceType = app.ServiceType,
// Creator = app.Creator,
// CreationTime = app.CreationTime,
// ModificationTime = app.ModificationTime,
// Modifier = app.Modifier,
// ResponsibilityUserIds = app.ResponsibilityUsers?.Select(x => x.UserId).ToList()
//}).OrderByDescending(app => app.ModificationTime)
//.ToList();

List<(EnvironmentClusterProjectApp EnvironmentClusterProjectApp,
int ProjectId,
Expand Down Expand Up @@ -193,6 +197,7 @@ public async Task GetAppListAsync(AppsQuery query)
CreationTime = appEnvironmentCluster.app.CreationTime,
ModificationTime = appEnvironmentCluster.app.ModificationTime,
Modifier = appEnvironmentCluster.app.Modifier,
ResponsibilityUserIds = appEnvironmentCluster.app.ResponsibilityUsers?.Select(x => x.UserId).ToList(),
EnvironmentClusters = appEnvironmentCluster.environmentClusters.Select(envCluster => new EnvironmentClusterDto
{
Id = envCluster.EnvironmentCluster.Id,
Expand Down Expand Up @@ -223,6 +228,7 @@ public async Task GetAppAsync(AppByTypesQuery query)
CreationTime = app.CreationTime,
ModificationTime = app.ModificationTime,
Modifier = app.Modifier,
ResponsibilityUserIds = app.ResponsibilityUsers?.Select(m => m.UserId).ToList()
}).ToList();
}
}
Original file line number Diff line number Diff line change
@@ -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.PM.Infrastructure.EFCore.PostgreSql.EntityConfigurations;

internal class AppResponsibilityUserConfigEntityTypeConfiguration : IEntityTypeConfiguration<AppResponsibilityUser>
{
public void Configure(EntityTypeBuilder<AppResponsibilityUser> builder)
{
builder.Property(m => m.CreateTime).HasDefaultValueSql("now()");
builder.HasOne(m => m.App).WithMany(m => m.ResponsibilityUsers);
}
}
Loading

0 comments on commit 2b51637

Please sign in to comment.