Browse Source

refactored IdentityApiResource and ApiResource repositories and added filter parameter

pull/4044/head
Akın Sabri Çam 6 years ago
parent
commit
7b93a8a76d
  1. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs
  2. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs
  3. 20
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  4. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs
  5. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  6. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

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, string sorting,
int skipCount, int skipCount,
int maxResultCount, int maxResultCount,
string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default 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, string sorting,
int skipCount, int skipCount,
int maxResultCount, int maxResultCount,
string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default 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.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Runtime.InteropServices.ComTypes;
namespace Volo.Abp.IdentityServer.ApiResources namespace Volo.Abp.IdentityServer.ApiResources
{ {
@ -24,30 +25,35 @@ namespace Volo.Abp.IdentityServer.ApiResources
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = from apiResource in DbSet.IncludeDetails(includeDetails) var query = from apiResource in DbSet.IncludeDetails(includeDetails)
where apiResource.Name == name where apiResource.Name == name
select apiResource; select apiResource;
return await query return await query
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<ApiResource>> GetListByScopesAsync( public virtual async Task<List<ApiResource>> GetListByScopesAsync(
string[] scopeNames, string[] scopeNames,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = from api in DbSet.IncludeDetails(includeDetails) var query = from api in DbSet.IncludeDetails(includeDetails)
where api.Scopes.Any(x => scopeNames.Contains(x.Name)) where api.Scopes.Any(x => scopeNames.Contains(x.Name))
select api; select api;
return await query.ToListAsync(GetCancellationToken(cancellationToken)); 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) CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc") .IncludeDetails(includeDetails)
.WhereIf(filter != null, x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .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 class IdentityResourceRepository : EfCoreRepository<IIdentityServerDbContext, IdentityResource, Guid>, IIdentityResourceRepository
{ {
public IdentityResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) public IdentityResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
@ -36,19 +36,22 @@ namespace Volo.Abp.IdentityServer.IdentityResources
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();
} }
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount,
bool includeDetails = false, CancellationToken cancellationToken = default) string filter, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.WhereIf(filter != null, x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc") .OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<IdentityResource> FindByNameAsync( public virtual async Task<IdentityResource> FindByNameAsync(
string name, string name,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await DbSet 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)); .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) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.WhereIf(filter != null,
x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? nameof(ApiResource.Name)) .OrderBy(sorting ?? nameof(ApiResource.Name))
.As<IMongoQueryable<ApiResource>>() .As<IMongoQueryable<ApiResource>>()
.PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount) .PageBy<ApiResource, IMongoQueryable<ApiResource>>(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() return await GetMongoQueryable()
.WhereIf(filter != null, x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityResource.Name)) .OrderBy(sorting ?? nameof(IdentityResource.Name))
.As<IMongoQueryable<IdentityResource>>() .As<IMongoQueryable<IdentityResource>>()
.PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount) .PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount)

Loading…
Cancel
Save