Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit c01d1a2

Browse files
committed
Included paging for Users and PersisedGrant
Ability to find Users by text
1 parent 504d350 commit c01d1a2

37 files changed

+10917
-81
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
* Now you can run through a docker! ❤️
44
* Unfortunately you need to change hosts for it. Because Authority URL. I can't do anything to face it. It's security feature from OAuth2 to keep same Authority name for each Token.
55

6+
* Pagination for Users and Persisted Grants
67

7-
* Update of main Context, JpProject
8-
* Removed previous components from MySql.Migrations and Sql.Migrations. Unified in same project.
8+
* Update of main DbContext, JpProject
9+
* Removed previous components from MySql.IdentityServer and Sql.IdentityServer. Unifying them at same project.
910

1011
* Client Page:
1112
* Changed Claims button to be under Token - Following Docs from [IdentityServer4](https://identityserver4.readthedocs.io/en/latest/reference/client.html#token)
1213
* Included Device Flow options
1314

1415
Updates:
1516
* @angular/cli to 7.3.6
16-
* @angular/core to 7.2.10 (ng update @angular/core, then it updated other dep's)|
17+
* @angular/core to 7.2.10 (ng update @angular/core, then updated other dep's by itself)|
1718
* @angular/language-service @ "7.2.10" (was "6.0.0")...
1819
* @angular/compiler-cli @ "7.2.10" (was "6.0.0")...
1920
* @angular/animations @ "7.2.10" (was "6.0.0")...

src/Backend/Jp.Application/Interfaces/IPersistedGrantAppService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using Jp.Application.ViewModels;
5+
using Jp.Domain.Core.ViewModels;
56

67
namespace Jp.Application.Interfaces
78
{
89
public interface IPersistedGrantAppService: IDisposable
910
{
10-
Task<IEnumerable<PersistedGrantViewModel>> GetPersistedGrants();
11+
Task<ListOfPersistedGrantViewModel> GetPersistedGrants(PagingViewModel paging);
1112
Task Remove(RemovePersistedGrantViewModel model);
1213
}
1314
}

src/Backend/Jp.Application/Interfaces/IUserManageAppService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Jp.Application.ViewModels;
66
using Jp.Application.ViewModels.RoleViewModels;
77
using Jp.Application.ViewModels.UserViewModels;
8+
using Jp.Domain.Core.ViewModels;
89
using Jp.Domain.Models;
910

1011
namespace Jp.Application.Interfaces
@@ -18,7 +19,7 @@ public interface IUserManageAppService : IDisposable
1819
Task RemoveAccount(RemoveAccountViewModel model);
1920
Task<bool> HasPassword(Guid userId);
2021
Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username);
21-
Task<IEnumerable<UserListViewModel>> GetUsers();
22+
2223
Task<UserViewModel> GetUserDetails(string username);
2324
Task<UserViewModel> GetUserAsync(Guid value);
2425
Task UpdateUser(UserViewModel model);
@@ -33,5 +34,6 @@ public interface IUserManageAppService : IDisposable
3334
Task RemoveLogin(RemoveUserLoginViewModel model);
3435
Task<IEnumerable<UserListViewModel>> GetUsersInRole(string[] role);
3536
Task ResetPassword(AdminChangePasswordViewodel model);
37+
Task<ListOfUsersViewModel> GetUsers(PagingViewModel page);
3638
}
3739
}

src/Backend/Jp.Application/Services/PersistedGrantAppService.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Threading.Tasks;
1010
using Jp.Domain.Commands.PersistedGrant;
11+
using Jp.Domain.Core.ViewModels;
1112

1213
namespace Jp.Application.Services
1314
{
@@ -32,11 +33,14 @@ public PersistedGrantAppService(IMapper mapper,
3233
_userService = userService;
3334
}
3435

35-
public async Task<IEnumerable<PersistedGrantViewModel>> GetPersistedGrants()
36+
public async Task<ListOfPersistedGrantViewModel> GetPersistedGrants(PagingViewModel paging)
3637
{
37-
var resultado = await _persistedGrantRepository.GetGrants();
38+
var resultado = await _persistedGrantRepository.GetGrants(paging);
39+
var total = await _persistedGrantRepository.Count();
3840
var subjects = await _userService.GetByIdAsync(resultado.Select(s => s.SubjectId).ToArray());
39-
return resultado.Select(s => new PersistedGrantViewModel(s.Key, s.Type, s.SubjectId, s.ClientId, s.CreationTime, s.Expiration, s.Data, subjects.FirstOrDefault(f => f.Id.ToString().ToLower() == s.SubjectId.ToLower())?.Email, subjects.FirstOrDefault(f => f.Id.ToString().ToLower() == s.SubjectId.ToLower())?.Picture));
41+
42+
var grants = resultado.Select(s => new PersistedGrantViewModel(s.Key, s.Type, s.SubjectId, s.ClientId, s.CreationTime, s.Expiration, s.Data, subjects.FirstOrDefault(f => f.Id.ToString().ToLower() == s.SubjectId.ToLower())?.Email, subjects.FirstOrDefault(f => f.Id.ToString().ToLower() == s.SubjectId.ToLower())?.Picture));
43+
return new ListOfPersistedGrantViewModel(grants, total);
4044
}
4145

4246
public Task Remove(RemovePersistedGrantViewModel model)

src/Backend/Jp.Application/Services/UserManagerAppService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Linq;
1414
using System.Threading.Tasks;
15+
using Jp.Domain.Core.ViewModels;
1516

1617
namespace Jp.Application.Services
1718
{
@@ -85,10 +86,11 @@ public async Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username)
8586
return _mapper.Map<IEnumerable<EventHistoryData>>(history);
8687
}
8788

88-
public async Task<IEnumerable<UserListViewModel>> GetUsers()
89+
public async Task<ListOfUsersViewModel> GetUsers(PagingViewModel paging)
8990
{
90-
var users = await _userService.GetUsers();
91-
return _mapper.Map<IEnumerable<UserListViewModel>>(users);
91+
var users = await _userService.GetUsers(paging);
92+
var total = await _userService.Count(paging.Search);
93+
return new ListOfUsersViewModel(_mapper.Map<IEnumerable<UserListViewModel>>(users), total);
9294
}
9395

9496
public async Task<UserViewModel> GetUserDetails(string username)

src/Backend/Jp.Application/ViewModels/PersistedGrantViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using IdentityServer4.Models;
34
using Jp.Domain.Interfaces;
45

@@ -78,4 +79,16 @@ public PersistedGrantViewModel(string key, string type, string subjectId, string
7879
Picture = picture;
7980
}
8081
}
82+
83+
public class ListOfPersistedGrantViewModel
84+
{
85+
public ListOfPersistedGrantViewModel(IEnumerable<PersistedGrantViewModel> persistedGrants,int total)
86+
{
87+
Total = total;
88+
PersistedGrants = persistedGrants;
89+
}
90+
91+
public int Total { get; set; }
92+
public IEnumerable<PersistedGrantViewModel> PersistedGrants { get; set; }
93+
}
8194
}

src/Backend/Jp.Application/ViewModels/UserViewModels/UserListViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.DataAnnotations;
34

45
namespace Jp.Application.ViewModels.UserViewModels
@@ -20,4 +21,17 @@ public class UserListViewModel
2021

2122
public Guid? Id { get; set; }
2223
}
24+
25+
public class ListOfUsersViewModel
26+
{
27+
public ListOfUsersViewModel(IEnumerable<UserListViewModel> collection, int total)
28+
{
29+
Total = total;
30+
Users = collection;
31+
}
32+
33+
public IEnumerable<UserListViewModel> Users { get; set; }
34+
35+
public int Total { get; set; }
36+
}
2337
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Jp.Domain.Core.ViewModels
2+
{
3+
public class PagingViewModel
4+
{
5+
public PagingViewModel(int quantity = 10, int page = 1, string search = null)
6+
{
7+
Quantity = quantity;
8+
Page = page;
9+
Search = search;
10+
}
11+
12+
public int Quantity { get; set; }
13+
public int Page { get; set; }
14+
public string Search { get; }
15+
}
16+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System.Collections.Generic;
22
using System.Threading.Tasks;
33
using IdentityServer4.EntityFramework.Entities;
4+
using Jp.Domain.Core.ViewModels;
45

56
namespace Jp.Domain.Interfaces
67
{
78
public interface IPersistedGrantRepository : IRepository<PersistedGrant>
89
{
9-
Task<List<PersistedGrant>> GetGrants();
10+
Task<List<PersistedGrant>> GetGrants(PagingViewModel paging);
11+
Task<int> Count();
1012
}
1113
}

src/Backend/Jp.Domain/Interfaces/IUserService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Security.Claims;
77
using System.Threading.Tasks;
8+
using Jp.Domain.Core.ViewModels;
89

910
namespace Jp.Domain.Interfaces
1011
{
@@ -26,7 +27,7 @@ public interface IUserService
2627
Task<bool> RemoveAccountAsync(RemoveAccountCommand request);
2728
Task<bool> HasPassword(Guid userId);
2829
Task<IEnumerable<User>> GetByIdAsync(params string[] id);
29-
Task<IEnumerable<User>> GetUsers();
30+
Task<IEnumerable<User>> GetUsers(PagingViewModel page);
3031
Task<User> FindByEmailAsync(string email);
3132
Task<User> FindByNameAsync(string username);
3233
Task<User> FindByProviderAsync(string provider, string providerUserId);
@@ -43,5 +44,6 @@ public interface IUserService
4344
Task<IEnumerable<User>> GetUserFromRole(string[] role);
4445
Task<bool> RemoveUserFromRole(string name, string username);
4546
Task<bool> ResetPasswordAsync(string username, string password);
47+
Task<int> Count(string search);
4648
}
4749
}

0 commit comments

Comments
 (0)