Browse Source

Merge pull request #4044 from abpframework/akin/refactored-some-entity-repositories-for-filtering-and-pagination

Akin/refactored some entity repositories for filtering and pagination
pull/4082/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
bfa9a3d360
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 34
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  3. 22
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  4. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs
  5. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs
  6. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs
  7. 20
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  8. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs
  9. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs
  10. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  11. 10
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs
  12. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

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

@ -18,6 +18,7 @@ namespace Volo.Abp.Identity
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);

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

@ -18,7 +18,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<IdentityRole> FindByNormalizedNameAsync(
string normalizedRoleName,
string normalizedRoleName,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -28,26 +28,30 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<List<IdentityRole>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool includeDetails = false,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string filter = null,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails)
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityRole.Name))
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await DbSet
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await DbSet
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
@ -59,6 +63,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public override IQueryable<IdentityRole> WithDetails()
{
return GetQueryable().IncludeDetails();
}
}
}
}

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

@ -26,33 +26,37 @@ namespace Volo.Abp.Identity.MongoDB
return await GetMongoQueryable().FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetListAsync(
public async Task<List<IdentityRole>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityRole.Name))
.As<IMongoQueryable<IdentityRole>>()
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
}
}
}

1
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs

@ -24,6 +24,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);

1
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs

@ -19,6 +19,7 @@ namespace Volo.Abp.IdentityServer.Clients
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);

1
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs

@ -18,6 +18,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);

20
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs

@ -8,6 +8,7 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
using System.Runtime.InteropServices.ComTypes;
namespace Volo.Abp.IdentityServer.ApiResources
{
@ -24,30 +25,35 @@ namespace Volo.Abp.IdentityServer.ApiResources
CancellationToken cancellationToken = default)
{
var query = from apiResource in DbSet.IncludeDetails(includeDetails)
where apiResource.Name == name
select apiResource;
where apiResource.Name == name
select apiResource;
return await query
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<ApiResource>> GetListByScopesAsync(
string[] scopeNames,
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from api in DbSet.IncludeDetails(includeDetails)
where api.Scopes.Any(x => scopeNames.Contains(x.Name))
select api;
where api.Scopes.Any(x => scopeNames.Contains(x.Name))
select api;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
public virtual async Task<List<ApiResource>> GetListAsync(
string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc")
.IncludeDetails(includeDetails)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

9
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual async Task<Client> FindByCliendIdAsync(
string clientId,
string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -28,11 +28,14 @@ namespace Volo.Abp.IdentityServer.Clients
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Client>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
public virtual async Task<List<Client>> GetListAsync(
string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? nameof(Client.ClientName) + " desc")
.IncludeDetails(includeDetails)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter))
.OrderBy(sorting ?? nameof(Client.ClientName) + " desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

13
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs

@ -13,7 +13,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
{
public class IdentityResourceRepository : EfCoreRepository<IIdentityServerDbContext, IdentityResource, Guid>, IIdentityResourceRepository
{
public IdentityResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider)
public IdentityResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider)
: base(dbContextProvider)
{
@ -36,19 +36,22 @@ namespace Volo.Abp.IdentityServer.IdentityResources
return GetQueryable().IncludeDetails();
}
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount,
bool includeDetails = false, CancellationToken cancellationToken = default)
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount,
string filter, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<IdentityResource> FindByNameAsync(
string name,
bool includeDetails = true,
string name,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await DbSet

6
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs

@ -33,10 +33,14 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? nameof(ApiResource.Name))
.As<IMongoQueryable<ApiResource>>()
.PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount)

10
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs

@ -22,7 +22,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
}
public virtual async Task<Client> FindByCliendIdAsync(
string clientId,
string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -30,13 +30,15 @@ namespace Volo.Abp.IdentityServer.MongoDB
}
public virtual async Task<List<Client>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(), x=>x.ClientId.Contains(filter))
.OrderBy(sorting ?? nameof(Client.ClientName))
.As<IMongoQueryable<Client>>()
.PageBy<Client, IMongoQueryable<Client>>(skipCount, maxResultCount)

5
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

@ -18,9 +18,12 @@ namespace Volo.Abp.IdentityServer.MongoDB
{
}
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false, CancellationToken cancellationToken = default)
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityResource.Name))
.As<IMongoQueryable<IdentityResource>>()
.PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount)

Loading…
Cancel
Save