refactored IdentityApiResource and ApiResource repositories and added filter parameter

pull/4044/head
Akın Sabri Çam 6 years ago
parent 44ddf5cded
commit 7b93a8a76d

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

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

@ -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 != null, x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

@ -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 != null, 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

@ -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 != null,
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)

@ -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 != null, 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