Skip to content

Commit

Permalink
Added count to user lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed May 19, 2020
1 parent 5a79e7f commit 48cf71c
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public interface IIdentityUserLookupAppService : IApplicationService
Task<UserData> FindByUserNameAsync(string userName);

Task<ListResultDto<UserData>> SearchAsync(UserLookupSearchInputDto input);

Task<long> GetCountAsync(UserLookupCountInputDto input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Volo.Abp.Identity
{
public class UserLookupCountInputDto
{
public string Filter { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public async Task<ListResultDto<UserData>> SearchAsync(UserLookupSearchInputDto
.ToList()
);
}

public async Task<long> GetCountAsync(UserLookupCountInputDto input)
{
return await UserLookupServiceProvider.GetCountAsync(input.Filter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,12 @@ public virtual async Task<List<IUserData>> SearchAsync(

return users.Select(u => u.ToAbpUserData()).ToList();
}

public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = new CancellationToken())
{
return await UserRepository.GetCountAsync(filter, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,18 @@ public async Task<List<IUserData>> SearchAsync(

return result.Items.Cast<IUserData>().ToList();
}

public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = new CancellationToken())
{
return await UserLookupAppService
.GetCountAsync(
new UserLookupCountInputDto
{
Filter = filter
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ public Task<ListResultDto<UserData>> SearchAsync(UserLookupSearchInputDto input)
{
return LookupAppService.SearchAsync(input);
}

[HttpGet]
[Route("count")]
public Task<long> GetCountAsync(UserLookupCountInputDto input)
{
return LookupAppService.GetCountAsync(input);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ Task<List<IUserData>> SearchAsync(
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default);

Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ namespace Volo.Abp.Users
public interface IUserLookupService<TUser>
where TUser : class, IUser
{
Task<TUser> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<TUser> FindByIdAsync(
Guid id,
CancellationToken cancellationToken = default
);

Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default);
Task<TUser> FindByUserNameAsync(
string userName,
CancellationToken cancellationToken = default
);

Task<List<IUserData>> SearchAsync(
string sorting = null,
string filter = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default);

Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ Task<List<TUser>> SearchAsync(
string filter = null,
CancellationToken cancellationToken = default
);

Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ public async Task<List<IUserData>> SearchAsync(
.ToList();
}

public async Task<long> 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<Task> func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,21 @@ public async Task<List<TUser>> SearchAsync(
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

public async Task<long> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,20 @@ public async Task<List<TUser>> SearchAsync(
.PageBy<TUser, IMongoQueryable<TUser>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

public async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf<TUser, IMongoQueryable<TUser>>(
!filter.IsNullOrWhiteSpace(),
u =>
u.UserName.Contains(filter) ||
u.Email.Contains(filter) ||
u.Name.Contains(filter) ||
u.Surname.Contains(filter)
)
.As<IMongoQueryable<TUser>>()
.CountAsync(GetCancellationToken(cancellationToken));
}
}
}

0 comments on commit 48cf71c

Please sign in to comment.