Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoleId> RoleIds { get; set; } = [];

public string RealName { get; set; } = string.Empty;
public int Status { get; set; }

public string Email { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -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<string> roles,string realName)
public class AdminUserResponse(AdminUserId id, string name, string phone, IEnumerable<string> 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<string> Roles { get; set; } = roles;

public IEnumerable<string> RoleIds { get; set; } = roles;

public string RealName { get; set; } = realName;

public int Status { get; set; } = status;

public DateTimeOffset CreatedAt { get; set; } = createdAt;

/// <summary>
/// 这里确认是使用name还是userName
/// </summary>
public string UserName { get; set; } = name;
public string Email { get; private set; } = email;
Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The 'Email' property uses a private setter, unlike the other properties with public setters; consider aligning the access modifiers for consistency across the response model.

Suggested change
public string Email { get; private set; } = email;
public string Email { get; set; } = email;

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ protected AdminUser()

public string RealName { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;

/// <summary>
/// 0:已禁用 1:已启用
/// </summary>
public int Status { get; private set; } = 1;

public DateTimeOffset CreatedAt { get; init; }
public virtual ICollection<AdminUserRole> Roles { get; } = [];

Expand All @@ -34,12 +40,15 @@ protected AdminUser()
public DateTimeOffset? DeletedAt { get; private set; }

public AdminUser(string name, string phone, string password,
IEnumerable<AdminUserRole> roles, IEnumerable<AdminUserPermission> permissions)
IEnumerable<AdminUserRole> roles, IEnumerable<AdminUserPermission> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public record CreateAdminUserCommand(
string Name,
string Phone,
string Password,
IEnumerable<AssignAdminUserRoleDto> RolesToBeAssigned)
IEnumerable<AssignAdminUserRoleDto> RolesToBeAssigned,
string RealName,
int Status,
string Email)
: ICommand<AdminUserId>;

public class CreateAdminUserCommandValidator : AbstractValidator<CreateAdminUserCommand>
Expand Down Expand Up @@ -42,7 +45,7 @@ public async Task<AdminUserId> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<PagedData<AdminUserResponse>> 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;
}
Expand All @@ -71,7 +71,7 @@ public async Task<PagedData<AdminUserResponse>> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<ResponseData<AdminUserId>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider defining a named constant or using an enum for the user status instead of the magic number '1', to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.

public AuthTests(MyWebApplicationFactory factory)
{
Expand Down
Loading