-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user overview in the admin module
- Loading branch information
Showing
14 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ public async Task Execute_WhenRequestIsValid_ShouldReturnValidResponse() | |
response.EnsureSuccessStatusCode(); | ||
var result = await response.Content | ||
.ReadFromJsonAsync<GetUsersResponse>(); | ||
result!.TotalCount.ShouldBe(13); | ||
result!.Users.Count.ShouldBe(10); | ||
result!.Users[1].Email.ShouldBe($"[email protected]"); | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
MadWorld/MadWorld.Frontend.Admin/Application/Users/IUserService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using MadWorld.Backend.Identity.Contracts.UserManagers; | ||
|
||
namespace MadWorld.Frontend.Admin.Application.Users; | ||
|
||
public interface IUserService | ||
{ | ||
Task<GetUsersResponse> GetUsers(int page); | ||
} |
28 changes: 28 additions & 0 deletions
28
MadWorld/MadWorld.Frontend.Admin/Application/Users/UserService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Net.Http.Json; | ||
using MadWorld.Backend.Identity.Contracts.UserManagers; | ||
using MadWorld.Shared.Blazor.Common; | ||
|
||
namespace MadWorld.Frontend.Admin.Application.Users; | ||
|
||
public class UserService : IUserService | ||
{ | ||
private const string Endpoint = "UserManager"; | ||
|
||
private readonly HttpClient _client; | ||
public UserService(IHttpClientFactory clientFactory) | ||
{ | ||
_client = clientFactory.CreateClient(ApiTypes.Identity); | ||
} | ||
|
||
public async Task<GetUsersResponse> GetUsers(int page) | ||
{ | ||
var response = await _client.GetAsync($"{Endpoint}/Users?page={page}"); | ||
|
||
if (!response.IsSuccessStatusCode) | ||
{ | ||
return new GetUsersResponse(); | ||
} | ||
|
||
return await response.Content.ReadFromJsonAsync<GetUsersResponse>() ?? new GetUsersResponse(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
MadWorld/MadWorld.Frontend.Admin/Application/Users/Users.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@using MadWorld.Backend.Identity.Contracts.UserManagers; | ||
|
||
@page "/Users" | ||
<div class="row"> | ||
<h3>All Users</h3> | ||
</div> | ||
<div class="row"> | ||
<RadzenDataGrid AllowFiltering="false" AllowSorting="false" AllowPaging="true" | ||
AllowVirtualization="true" Style="height:600px" | ||
PageSize="10" Count="@_response.TotalCount" Page="OnPage" | ||
LoadData="LoadData" | ||
PagerPosition="PagerPosition.Bottom" | ||
PagerHorizontalAlign="HorizontalAlign.Center" | ||
ShowPagingSummary="true" Data="@_response.Users" TItem="UserContract"> | ||
<Columns> | ||
<RadzenDataGridColumn TItem="UserContract" Property="Email" Title="Email" Width="150px" /> | ||
</Columns> | ||
</RadzenDataGrid> | ||
</div> |
38 changes: 38 additions & 0 deletions
38
MadWorld/MadWorld.Frontend.Admin/Application/Users/Users.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using MadWorld.Backend.Identity.Contracts.UserManagers; | ||
using Microsoft.AspNetCore.Components; | ||
using Radzen; | ||
|
||
namespace MadWorld.Frontend.Admin.Application.Users; | ||
|
||
public partial class Users | ||
{ | ||
[Inject] | ||
public IUserService UserService { get; set; } = null!; | ||
|
||
private GetUsersResponse _response = new(); | ||
|
||
private int _currentPage = 0; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await LoadUsers(); | ||
|
||
await base.OnInitializedAsync(); | ||
} | ||
|
||
private Task LoadData(LoadDataArgs _) => Task.CompletedTask; | ||
|
||
private async Task OnPage(PagerEventArgs args) | ||
{ | ||
if (_currentPage != args.PageIndex) | ||
{ | ||
_currentPage = args.PageIndex; | ||
await LoadUsers(); | ||
} | ||
} | ||
|
||
private async Task LoadUsers() | ||
{ | ||
_response = await UserService.GetUsers(_currentPage); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
MadWorld/MadWorld.Frontend.Admin/Extensions/WebAssemblyHostBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using MadWorld.Frontend.Admin.Application.Users; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
|
||
namespace MadWorld.Frontend.Admin.Extensions; | ||
|
||
public static class WebAssemblyHostBuilderExtensions | ||
{ | ||
public static void AddApplication(this WebAssemblyHostBuilder builder) | ||
{ | ||
builder.Services.AddScoped<IUserService, UserService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters