-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2b511b
commit 514a972
Showing
17 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/DashboardDataResponse.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData | ||
{ | ||
public class DashboardDataResponse | ||
{ | ||
public int ProductCount { get; set; } | ||
public int BrandCount { get; set; } | ||
public int UserCount { get; set; } | ||
public int RoleCount { get; set; } | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/GetDashboardDataQuery.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,41 @@ | ||
using BlazorHero.CleanArchitecture.Application.Interfaces.Repositories; | ||
using BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity; | ||
using BlazorHero.CleanArchitecture.Domain.Entities.Catalog; | ||
using BlazorHero.CleanArchitecture.Shared.Wrapper; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData | ||
{ | ||
public class GetDashboardDataQuery : IRequest<Result<DashboardDataResponse>> | ||
{ | ||
public class GetDashboardDataQueryHandler : IRequestHandler<GetDashboardDataQuery, Result<DashboardDataResponse>> | ||
{ | ||
private readonly IUnitOfWork _unitOfWork; | ||
private readonly IUserService _userService; | ||
private readonly IRoleService _roleService; | ||
|
||
public GetDashboardDataQueryHandler(IUnitOfWork unitOfWork, IUserService userService, IRoleService roleService) | ||
{ | ||
_unitOfWork = unitOfWork; | ||
_userService = userService; | ||
_roleService = roleService; | ||
} | ||
public async Task<Result<DashboardDataResponse>> Handle(GetDashboardDataQuery query, CancellationToken cancellationToken) | ||
{ | ||
var response = new DashboardDataResponse(); | ||
response.ProductCount = await _unitOfWork.Repository<Product>().Entities.CountAsync(); | ||
response.BrandCount = await _unitOfWork.Repository<Brand>().Entities.CountAsync(); | ||
response.UserCount = await _userService.GetCountAsync(); | ||
response.RoleCount = await _roleService.GetCountAsync(); | ||
return Result<DashboardDataResponse>.Success(response); | ||
} | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/DashboardManager.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 BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData; | ||
using BlazorHero.CleanArchitecture.Client.Infrastructure.Extensions; | ||
using BlazorHero.CleanArchitecture.Shared.Wrapper; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard | ||
{ | ||
public class DashboardManager : IDashboardManager | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public DashboardManager(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<IResult<DashboardDataResponse>> GetDataAsync() | ||
{ | ||
try | ||
{ | ||
var response = await _httpClient.GetAsync(Routes.DashboardEndpoint.GetData); | ||
var data = await response.ToResult<DashboardDataResponse>(); | ||
return data; | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
throw; | ||
} | ||
|
||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/IDashboardManager.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 BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData; | ||
using BlazorHero.CleanArchitecture.Shared.Wrapper; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard | ||
{ | ||
public interface IDashboardManager : IManager | ||
{ | ||
Task<IResult<DashboardDataResponse>> GetDataAsync(); | ||
|
||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/DashboardEndpoint.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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Routes | ||
{ | ||
public class DashboardEndpoint | ||
{ | ||
public static string GetData = "api/v1/dashboard"; | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
BlazorHero.CleanArchitecture/Client/Pages/Content/Dashboard.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,75 @@ | ||
@page "/dashboard" | ||
@inject Microsoft.Extensions.Localization.IStringLocalizer<Dashboard> localizer | ||
<HeroTitle Title="@localizer["Dashboard"]" Description="@localizer["Quick Insights."]" /> | ||
<MudGrid> | ||
<MudItem xs="12" sm="6" md="3"> | ||
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;"> | ||
<MudIcon Icon="@Icons.Material.Filled.Euro" Color="Color.Primary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon> | ||
<div> | ||
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Products</MudText> | ||
<MudText Typo="Typo.h5">@ProductCount</MudText> | ||
</div> | ||
</MudPaper> | ||
</MudItem> | ||
<MudItem xs="12" sm="6" md="3"> | ||
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;"> | ||
<MudIcon Icon="@Icons.Material.Filled.Home" Color="Color.Secondary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon> | ||
<div> | ||
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Brands</MudText> | ||
<MudText Typo="Typo.h5">@BrandCount</MudText> | ||
</div> | ||
</MudPaper> | ||
</MudItem> | ||
<MudItem xs="12" sm="6" md="3"> | ||
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;"> | ||
<MudIcon Icon="@Icons.Material.Filled.Public" Color="Color.Success" Class="mx-4" Style="width:54px; height:54px;"></MudIcon> | ||
<div> | ||
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Registered Users</MudText> | ||
<MudText Typo="Typo.h5">@UserCount</MudText> | ||
</div> | ||
</MudPaper> | ||
</MudItem> | ||
<MudItem xs="12" sm="6" md="3"> | ||
<MudPaper Elevation="25" Class="d-flex flex-row pt-6 pb-4" Style="height:100px;"> | ||
<MudIcon Icon="@Icons.Custom.Uncategorized.Radioactive" Color="Color.Warning" Class="mx-4" Style="width:54px; height:54px;"></MudIcon> | ||
<div> | ||
<MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">Registered Roles</MudText> | ||
<MudText Typo="Typo.h5">@RoleCount</MudText> | ||
</div> | ||
</MudPaper> | ||
</MudItem> | ||
<MudItem xs="12" sm="8"> | ||
<MudPaper Elevation="25" Class="pa-4" Style="height:300px;"> | ||
Charts comming soon ish... | ||
</MudPaper> | ||
</MudItem> | ||
<MudItem xs="12" sm="4"> | ||
<MudPaper Elevation="25" Class="pa-4" Style="height:300px;"> | ||
Charts comming soon ish... | ||
</MudPaper> | ||
</MudItem> | ||
</MudGrid> | ||
@code{ | ||
|
||
[Parameter] | ||
public int ProductCount { get; set; } | ||
[Parameter] | ||
public int BrandCount { get; set; } | ||
[Parameter] | ||
public int UserCount { get; set; } | ||
[Parameter] | ||
public int RoleCount { get; set; } | ||
protected override async Task OnInitializedAsync() => await LoadDataAsync(); | ||
|
||
private async Task LoadDataAsync() | ||
{ | ||
var data = await _dashboardManager.GetDataAsync(); | ||
if(data.Succeeded) | ||
{ | ||
ProductCount = data.Data.ProductCount; | ||
BrandCount = data.Data.BrandCount; | ||
UserCount = data.Data.UserCount; | ||
RoleCount = data.Data.RoleCount; | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
BlazorHero.CleanArchitecture/Server/Controllers/v1/DashboardController.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,23 @@ | ||
using BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorHero.CleanArchitecture.Server.Controllers.v1 | ||
{ | ||
[ApiController] | ||
public class DashboardController : BaseApiController<DashboardController> | ||
{ | ||
[Authorize] | ||
[HttpGet] | ||
public async Task<IActionResult> GetDataAsync() | ||
{ | ||
var result = await _mediator.Send(new GetDashboardDataQuery()); | ||
return Ok(result); | ||
} | ||
} | ||
} |