From 48cf71c0597ce70bfd675954b30a7a4850c33f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 19 May 2020 22:46:31 +0300 Subject: [PATCH] Added count to user lookup --- .../Identity/IIdentityUserLookupAppService.cs | 2 ++ .../Abp/Identity/UserLookupCountInputDto.cs | 7 +++++++ .../Abp/Identity/UserLookupSearchInputDto.cs | 4 +--- .../Identity/IdentityUserLookupAppService.cs | 5 +++++ ...sitoryExternalUserLookupServiceProvider.cs | 7 +++++++ .../HttpClientIdentityUserLookupService.cs | 13 ++++++++++++ .../Identity/IdentityUserLookupController.cs | 7 +++++++ .../IExternalUserLookupServiceProvider.cs | 5 +++++ .../Volo/Abp/Users/IUserLookupService.cs | 14 +++++++++++-- .../Volo/Abp/Users/IUserRepository.cs | 4 ++++ .../Volo/Abp/Users/UserLookupService.cs | 20 +++++++++++++++++++ .../EfCoreAbpUserRepositoryBase.cs | 16 +++++++++++++++ .../Users/MongoDB/MongoUserRepositoryBase.cs | 15 ++++++++++++++ 13 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupCountInputDto.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs index f3c3a3bc53..2b1b1de331 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs @@ -13,5 +13,7 @@ namespace Volo.Abp.Identity Task FindByUserNameAsync(string userName); Task> SearchAsync(UserLookupSearchInputDto input); + + Task GetCountAsync(UserLookupCountInputDto input); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupCountInputDto.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupCountInputDto.cs new file mode 100644 index 0000000000..c8972615df --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupCountInputDto.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Identity +{ + public class UserLookupCountInputDto + { + public string Filter { get; set; } + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupSearchInputDto.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupSearchInputDto.cs index b48e526576..cc9835afd1 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupSearchInputDto.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UserLookupSearchInputDto.cs @@ -2,10 +2,8 @@ namespace Volo.Abp.Identity { - public class UserLookupSearchInputDto : PagedResultRequestDto, ISortedResultRequest + public class UserLookupSearchInputDto : PagedAndSortedResultRequestDto { - public string Sorting { get; set; } - public string Filter { get; set; } } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs index 4c1ee1ffba..ec9aaa3805 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs @@ -55,5 +55,10 @@ namespace Volo.Abp.Identity .ToList() ); } + + public async Task GetCountAsync(UserLookupCountInputDto input) + { + return await UserLookupServiceProvider.GetCountAsync(input.Filter); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs index c3c73db342..c0fb15d80c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs @@ -66,5 +66,12 @@ namespace Volo.Abp.Identity return users.Select(u => u.ToAbpUserData()).ToList(); } + + public async Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = new CancellationToken()) + { + return await UserRepository.GetCountAsync(filter, cancellationToken); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs index 3a14cb2b10..28859c6c1f 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs @@ -47,5 +47,18 @@ namespace Volo.Abp.Identity return result.Items.Cast().ToList(); } + + public async Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = new CancellationToken()) + { + return await UserLookupAppService + .GetCountAsync( + new UserLookupCountInputDto + { + Filter = filter + } + ); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs index 70dcaaa300..75fc20a520 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs @@ -40,5 +40,12 @@ namespace Volo.Abp.Identity { return LookupAppService.SearchAsync(input); } + + [HttpGet] + [Route("count")] + public Task GetCountAsync(UserLookupCountInputDto input) + { + return LookupAppService.GetCountAsync(input); + } } } diff --git a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/IExternalUserLookupServiceProvider.cs b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/IExternalUserLookupServiceProvider.cs index 67c9964d95..bd601b25d3 100644 --- a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/IExternalUserLookupServiceProvider.cs +++ b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/IExternalUserLookupServiceProvider.cs @@ -17,5 +17,10 @@ namespace Volo.Abp.Users int maxResultCount = int.MaxValue, int skipCount = 0, CancellationToken cancellationToken = default); + + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default + ); } } \ No newline at end of file diff --git a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserLookupService.cs b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserLookupService.cs index d07eb82b9e..afa45fc81a 100644 --- a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserLookupService.cs +++ b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserLookupService.cs @@ -8,9 +8,15 @@ namespace Volo.Abp.Users public interface IUserLookupService where TUser : class, IUser { - Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default); + Task FindByIdAsync( + Guid id, + CancellationToken cancellationToken = default + ); - Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default); + Task FindByUserNameAsync( + string userName, + CancellationToken cancellationToken = default + ); Task> SearchAsync( string sorting = null, @@ -18,5 +24,9 @@ namespace Volo.Abp.Users int maxResultCount = int.MaxValue, int skipCount = 0, CancellationToken cancellationToken = default); + + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default); } } diff --git a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserRepository.cs b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserRepository.cs index fc0412c734..268805e43f 100644 --- a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserRepository.cs +++ b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/IUserRepository.cs @@ -21,5 +21,9 @@ namespace Volo.Abp.Users string filter = null, CancellationToken cancellationToken = default ); + + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/UserLookupService.cs b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/UserLookupService.cs index 20c6193a25..8311263f3e 100644 --- a/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/UserLookupService.cs +++ b/modules/users/src/Volo.Abp.Users.Domain/Volo/Abp/Users/UserLookupService.cs @@ -173,6 +173,26 @@ namespace Volo.Abp.Users .ToList(); } + public async Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default) + { + if (ExternalUserLookupServiceProvider != null) + { + return await ExternalUserLookupServiceProvider + .GetCountAsync( + filter, + cancellationToken + ); + } + + return await _userRepository + .GetCountAsync( + filter, + cancellationToken + ); + } + protected abstract TUser CreateUser(IUserData externalUser); private async Task WithNewUowAsync(Func func) diff --git a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs index f84577406e..e1e6c33768 100644 --- a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs +++ b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs @@ -50,5 +50,21 @@ namespace Volo.Abp.Users.EntityFrameworkCore .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public async Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default) + { + return await DbSet + .WhereIf( + !filter.IsNullOrWhiteSpace(), + u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + u.Name.Contains(filter) || + u.Surname.Contains(filter) + ) + .CountAsync(GetCancellationToken(cancellationToken)); + } } } \ No newline at end of file diff --git a/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs b/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs index abb9a6c58e..39c22d4ed7 100644 --- a/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs +++ b/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs @@ -52,5 +52,20 @@ namespace Volo.Abp.Users.MongoDB .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await GetMongoQueryable() + .WhereIf>( + !filter.IsNullOrWhiteSpace(), + u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + u.Name.Contains(filter) || + u.Surname.Contains(filter) + ) + .As>() + .CountAsync(GetCancellationToken(cancellationToken)); + } } } \ No newline at end of file