From 575826ddd2bbc7f30a28f3eebd3fc333439c7c7c Mon Sep 17 00:00:00 2001 From: littleMonk <1693245871@qq.com> Date: Mon, 5 May 2025 01:12:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Requests/CreateAdminUserRequest.cs | 5 +++++ .../Responses/AdminUserResponse.cs | 14 +++++++++----- .../Identity/AdminUserAggregate/AdminUser.cs | 11 ++++++++++- .../Identity/Admin/CreateAdminUserCommand.cs | 7 +++++-- .../Queries/Identity/Admin/AdminUserQuery.cs | 4 ++-- .../Identity/Admin/AdminUserController.cs | 2 +- .../Extensions/SeedDatabaseExtension.cs | 2 +- .../Identity/AdminUserTests.cs | 2 +- .../Identity/AuthTests.cs | 2 +- 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs b/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs index 8439230..8f7ea14 100644 --- a/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs +++ b/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs @@ -9,4 +9,9 @@ public class CreateAdminUserRequest [Required] public string Phone { get; set; } = string.Empty; [Required] public string PassWord { get; set; } = string.Empty; public IEnumerable RoleIds { get; set; } = []; + + public string RealName { get; set; } = string.Empty; + public int Status { get; set; } + + public string Email { get; private set; } = string.Empty; } \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs b/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs index d3070de..d68287f 100644 --- a/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs +++ b/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs @@ -1,18 +1,22 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; +using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; namespace NetCorePal.D3Shop.Admin.Shared.Responses; -public class AdminUserResponse(AdminUserId id, string name, string phone, IEnumerable roles,string realName) +public class AdminUserResponse(AdminUserId id, string name, string phone, IEnumerable roles, string realName,int status,string email, DateTimeOffset createdAt) { public AdminUserId Id { get; } = id; public string Name { get; set; } = name; public string Phone { get; set; } = phone; public IEnumerable Roles { get; set; } = roles; + + public IEnumerable RoleIds { get; set; } = roles; + public string RealName { get; set; } = realName; + public int Status { get; set; } = status; + + public DateTimeOffset CreatedAt { get; set; } = createdAt; - /// - /// 这里确认是使用name还是userName - /// - public string UserName { get; set; } = name; + public string Email { get; private set; } = email; } diff --git a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUser.cs b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUser.cs index abcd348..f6af4d3 100644 --- a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUser.cs +++ b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUser.cs @@ -22,6 +22,12 @@ protected AdminUser() public string RealName { get; private set; } = string.Empty; public string Email { get; private set; } = string.Empty; + + /// + /// 0:已禁用 1:已启用 + /// + public int Status { get; private set; } = 1; + public DateTimeOffset CreatedAt { get; init; } public virtual ICollection Roles { get; } = []; @@ -34,12 +40,15 @@ protected AdminUser() public DateTimeOffset? DeletedAt { get; private set; } public AdminUser(string name, string phone, string password, - IEnumerable roles, IEnumerable permissions) + IEnumerable roles, IEnumerable permissions, string realName, int status, string email) { CreatedAt = DateTimeOffset.Now; Name = name; Phone = phone; Password = password; + RealName = realName; + Status = status; + Email = email; foreach (var adminUserRole in roles) { Roles.Add(adminUserRole); diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Admin/CreateAdminUserCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Admin/CreateAdminUserCommand.cs index 24b24a2..95ed4be 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Admin/CreateAdminUserCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Admin/CreateAdminUserCommand.cs @@ -11,7 +11,10 @@ public record CreateAdminUserCommand( string Name, string Phone, string Password, - IEnumerable RolesToBeAssigned) + IEnumerable RolesToBeAssigned, + string RealName, + int Status, + string Email) : ICommand; public class CreateAdminUserCommandValidator : AbstractValidator @@ -42,7 +45,7 @@ public async Task Handle(CreateAdminUserCommand request, Cancellati var adminUser = new AdminUser(request.Name, request.Phone, request.Password, - adminUserRoles, adminUserPermissions); + adminUserRoles, adminUserPermissions,request.RealName, request.Status, request.Email); await adminUserRepository.AddAsync(adminUser, cancellationToken); return adminUser.Id; diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/Admin/AdminUserQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/Admin/AdminUserQuery.cs index e2bd4e8..8280e71 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/Admin/AdminUserQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/Admin/AdminUserQuery.cs @@ -60,7 +60,7 @@ public async Task> GetAllAdminUsersAsync(AdminUserQ .WhereIf(!queryRequest.Name.IsNullOrWhiteSpace(), au => au.Name.Contains(queryRequest.Name!)) .WhereIf(!queryRequest.Phone.IsNullOrWhiteSpace(), au => au.Phone.Contains(queryRequest.Phone!)) .OrderBy(au => au.Id) - .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone, au.Roles.Select(r => r.RoleName),au.RealName)) + .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone, au.Roles.Select(r => r.RoleName),au.RealName,au.Status,au.Email,au.CreatedAt)) .ToPagedDataAsync(queryRequest, cancellationToken); return adminUsers; } @@ -71,7 +71,7 @@ public async Task> GetAllAdminUsersAsync(AdminUserQ { var adminUsers = await AdminUserSet.AsNoTracking() .Where(x => x.Id == id) - .Select(au => new AdminUserResponse(au.Id, au.Name, au.Name, au.Roles.Select(r => r.RoleName), au.RealName)) + .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone, au.Roles.Select(r => r.RoleName), au.RealName, au.Status, au.Email, au.CreatedAt)) .FirstOrDefaultAsync(cancellationToken); return adminUsers; } diff --git a/src/NetCorePal.D3Shop.Web/Controllers/Identity/Admin/AdminUserController.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Admin/AdminUserController.cs index 117cfe7..bd31b60 100644 --- a/src/NetCorePal.D3Shop.Web/Controllers/Identity/Admin/AdminUserController.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Admin/AdminUserController.cs @@ -37,7 +37,7 @@ public async Task> CreateAdminUser([FromBody] CreateAd var password = PasswordHasher.HashPassword(request.PassWord); var adminUserId = await mediator.Send( - new CreateAdminUserCommand(request.Name, request.Phone, password, rolesToBeAssigned), + new CreateAdminUserCommand(request.Name, request.Phone, password, rolesToBeAssigned,request.RealName,request.Status,request.Email), CancellationToken); return adminUserId.AsResponseData(); diff --git a/src/NetCorePal.D3Shop.Web/Extensions/SeedDatabaseExtension.cs b/src/NetCorePal.D3Shop.Web/Extensions/SeedDatabaseExtension.cs index 55daf08..7398871 100644 --- a/src/NetCorePal.D3Shop.Web/Extensions/SeedDatabaseExtension.cs +++ b/src/NetCorePal.D3Shop.Web/Extensions/SeedDatabaseExtension.cs @@ -16,7 +16,7 @@ internal static IApplicationBuilder SeedDatabase(this IApplicationBuilder app) if (!dbContext.AdminUsers.Any(u => u.Name == AppDefaultCredentials.Name)) { var adminUser = new AdminUser(AppDefaultCredentials.Name, "", - PasswordHasher.HashPassword(AppDefaultCredentials.Password), [], []); + PasswordHasher.HashPassword(AppDefaultCredentials.Password), [], [], "", 1, ""); dbContext.AdminUsers.Add(adminUser); dbContext.SaveChanges(); } diff --git a/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs b/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs index a3bbff6..e81b84e 100644 --- a/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs +++ b/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs @@ -5,7 +5,7 @@ namespace NetCorePal.D3Shop.Domain.Tests.Identity { public class AdminUserTests { - private readonly AdminUser _testUser = new("test", "1", "", [], []); + private readonly AdminUser _testUser = new("test", "1", "", [], [],"",1,""); [Fact] public void EditRole_Test() diff --git a/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs b/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs index 93534a3..a6802a2 100644 --- a/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs +++ b/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs @@ -10,7 +10,7 @@ namespace NetCorePal.D3Shop.Web.Tests.Identity; public class AuthTests { private readonly HttpClient _client; - private readonly AdminUser _testUser = new("Test", "", "", [], []); + private readonly AdminUser _testUser = new("Test", "", "", [], [], "", 1, ""); public AuthTests(MyWebApplicationFactory factory) { From 72fd07376d29e18e7a14d7f40242548f00561e2f Mon Sep 17 00:00:00 2001 From: littleMonk <1693245871@qq.com> Date: Mon, 12 May 2025 20:07:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Demail=E7=9A=84private?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Requests/CreateAdminUserRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs b/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs index 8f7ea14..bac6dd9 100644 --- a/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs +++ b/src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateAdminUserRequest.cs @@ -13,5 +13,5 @@ public class CreateAdminUserRequest public string RealName { get; set; } = string.Empty; public int Status { get; set; } - public string Email { get; private set; } = string.Empty; + public string Email { get; set; } = string.Empty; } \ No newline at end of file