Browse Source

Remove GetAllListWithUserCountAsync method

pull/17380/head
liangshiwei 3 years ago
parent
commit
426eefaa96
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 17
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  3. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  4. 13
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -14,10 +14,6 @@ public interface IIdentityRoleRepository : IBasicRepository<IdentityRole, Guid>
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<RoleWithUserCount>> GetAllListWithUserCountAsync(
CancellationToken cancellationToken = default
);
Task<List<RoleWithUserCount>> GetListWithUserCountAsync( Task<List<RoleWithUserCount>> GetListWithUserCountAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,

17
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -28,23 +28,6 @@ public class EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext,
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
} }
public async Task<List<RoleWithUserCount>> GetAllListWithUserCountAsync(CancellationToken cancellationToken = default)
{
var roles = await GetListInternalAsync(cancellationToken: cancellationToken);
var roleIds = roles.Select(x => x.Id).ToList();
var userCount = await (await GetDbContextAsync()).Set<IdentityUserRole>()
.Where(userRole => roleIds.Contains(userRole.RoleId))
.GroupBy(userRole => userRole.RoleId)
.Select(x => new
{
RoleId = x.Key,
Count = x.Count()
})
.ToListAsync(GetCancellationToken(cancellationToken));
return roles.Select(role => new RoleWithUserCount(role, userCount.FirstOrDefault(x => x.RoleId == role.Id)?.Count ?? 0)).ToList();
}
public async Task<List<RoleWithUserCount>> GetListWithUserCountAsync( public async Task<List<RoleWithUserCount>> GetListWithUserCountAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,

18
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -28,24 +28,6 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
} }
public async Task<List<RoleWithUserCount>> GetAllListWithUserCountAsync(CancellationToken cancellationToken = default)
{
var roles = await GetListInternalAsync(cancellationToken : cancellationToken);
var roleIds = roles.Select(x => x.Id).ToList();
var userCount = await (await GetMongoQueryableAsync<IdentityUser>(cancellationToken))
.Where(user => user.Roles.Any(role => roleIds.Contains(role.RoleId)))
.SelectMany(user => user.Roles)
.GroupBy(userRole => userRole.RoleId)
.Select(x => new
{
RoleId = x.Key,
Count = x.Count()
})
.ToListAsync(GetCancellationToken(cancellationToken));
return roles.Select(role => new RoleWithUserCount(role, userCount.FirstOrDefault(x => x.RoleId == role.Id)?.Count ?? 0)).ToList();
}
public async Task<List<RoleWithUserCount>> GetListWithUserCountAsync( public async Task<List<RoleWithUserCount>> GetListWithUserCountAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,

13
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

@ -68,9 +68,9 @@ public abstract class IdentityRoleRepository_Tests<TStartupModule> : AbpIdentity
} }
[Fact] [Fact]
public async Task GetAllListWithUserCountAsync() public async Task GetListWithUserCountAsync()
{ {
var roles = await RoleRepository.GetAllListWithUserCountAsync(); var roles = await RoleRepository.GetListWithUserCountAsync();
roles.Count.ShouldBe(4); roles.Count.ShouldBe(4);
roles.ShouldContain(r => r.Role.Name == "admin" && r.UserCount == 2); roles.ShouldContain(r => r.Role.Name == "admin" && r.UserCount == 2);
@ -78,13 +78,4 @@ public abstract class IdentityRoleRepository_Tests<TStartupModule> : AbpIdentity
roles.ShouldContain(r => r.Role.Name == "supporter" && r.UserCount == 2); roles.ShouldContain(r => r.Role.Name == "supporter" && r.UserCount == 2);
roles.ShouldContain(r => r.Role.Name == "manager" && r.UserCount == 1); roles.ShouldContain(r => r.Role.Name == "manager" && r.UserCount == 1);
} }
[Fact]
public async Task GetListWithUserCountAsync()
{
var roles = await RoleRepository.GetListWithUserCountAsync(filter: "admin");
roles.Count.ShouldBe(1);
roles.ShouldContain(r => r.Role.Name == "admin" && r.UserCount == 2);
}
} }

Loading…
Cancel
Save