-
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.
- Loading branch information
Showing
19 changed files
with
158 additions
and
15 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
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
18 changes: 18 additions & 0 deletions
18
MadWorld/MadWorld.Frontend.Application/Blogs/GetBlogsUseCase.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,18 @@ | ||
using MadWorld.Frontend.Domain.Blogs; | ||
using MadWorld.Shared.Contracts.Anonymous.Blog; | ||
|
||
namespace MadWorld.Frontend.Application.Blogs; | ||
|
||
public class GetBlogsUseCase : IGetBlogsUseCase | ||
{ | ||
private readonly IBlogService _service; | ||
public GetBlogsUseCase(IBlogService service) | ||
{ | ||
_service = service; | ||
} | ||
|
||
public async Task<GetBlogsResponse> GetBlogsAsync(int pageNumber) | ||
{ | ||
return await _service.GetBlogs(pageNumber); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using MadWorld.Shared.Contracts.Anonymous.Blog; | ||
|
||
namespace MadWorld.Frontend.Domain.Blogs; | ||
|
||
public interface IBlogService | ||
{ | ||
Task<GetBlogsResponse> GetBlogs(int pageNumber); | ||
} |
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.Shared.Contracts.Anonymous.Blog; | ||
|
||
namespace MadWorld.Frontend.Domain.Blogs; | ||
|
||
public interface IGetBlogsUseCase | ||
{ | ||
Task<GetBlogsResponse> GetBlogsAsync(int pageNumber); | ||
} |
22 changes: 22 additions & 0 deletions
22
MadWorld/MadWorld.Frontend.Infrastructure/BlogService/BlogService.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,22 @@ | ||
using System.Net.Http.Json; | ||
using MadWorld.Frontend.Domain.Api; | ||
using MadWorld.Frontend.Domain.Blogs; | ||
using MadWorld.Shared.Contracts.Anonymous.Blog; | ||
|
||
namespace MadWorld.Frontend.Infrastructure.BlogService; | ||
|
||
public class BlogService : IBlogService | ||
{ | ||
private const string Endpoint = "Blogs"; | ||
|
||
private readonly HttpClient _client; | ||
|
||
public BlogService(IHttpClientFactory clientFactory) | ||
{ | ||
_client = clientFactory.CreateClient(ApiTypes.MadWorldApiAuthorized); | ||
} | ||
public async Task<GetBlogsResponse> GetBlogs(int pageNumber) | ||
{ | ||
return await _client.GetFromJsonAsync<GetBlogsResponse>($"{Endpoint}/{pageNumber}") ?? new GetBlogsResponse(0, Array.Empty<BlogContract>()); | ||
} | ||
} |
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: 22 additions & 1 deletion
23
MadWorld/MadWorld.Frontend.UI.Admin/Pages/Blogs/BlogOverview.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 |
---|---|---|
@@ -1,2 +1,23 @@ | ||
@using MadWorld.Frontend.UI.Shared.Components | ||
@using MadWorld.Shared.Contracts.Anonymous.Blog | ||
|
||
@page "/Blogs" | ||
<h3>BlogOverview</h3> | ||
|
||
<PageTitle>Blog Overview</PageTitle> | ||
|
||
<h3>Blog Overview</h3> | ||
@if (_isReady) | ||
{ | ||
<RadzenDataGrid @ref="dataGrid" IsLoading=@_isLoading Count="_totalRecords" Data="@_blogs" | ||
LoadData="@LoadData" AllowSorting="false" AllowFiltering="false" | ||
AllowPaging="true" PageSize="20" PagerHorizontalAlign="HorizontalAlign.Center" | ||
TItem="BlogContract" ShowPagingSummary="true" PagingSummaryFormat="@pagingSummaryFormat"> | ||
<Columns> | ||
<RadzenDataGridColumn TItem="BlogContract" Property="Title" Title="Title" /> | ||
</Columns> | ||
</RadzenDataGrid> | ||
} | ||
else | ||
{ | ||
<LoadingSpinner /> | ||
} |
48 changes: 47 additions & 1 deletion
48
MadWorld/MadWorld.Frontend.UI.Admin/Pages/Blogs/BlogOverview.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 |
---|---|---|
@@ -1,6 +1,52 @@ | ||
using JetBrains.Annotations; | ||
using MadWorld.Frontend.Domain.Blogs; | ||
using MadWorld.Shared.Contracts.Anonymous.Blog; | ||
using Microsoft.AspNetCore.Components; | ||
using Radzen; | ||
using Radzen.Blazor; | ||
|
||
namespace MadWorld.Frontend.UI.Admin.Pages.Blogs; | ||
|
||
[UsedImplicitly] | ||
public partial class BlogOverview | ||
{ | ||
|
||
private string pagingSummaryFormat = "Displaying page {0} of {1} <b>(total {2} records)</b>"; | ||
private RadzenDataGrid<BlogContract> dataGrid; | ||
|
||
private int PagePosition = 0; | ||
|
||
private bool _isReady; | ||
private bool _isLoading => !_isReady; | ||
|
||
private int _totalRecords = 0; | ||
private IReadOnlyCollection<BlogContract> _blogs = Array.Empty<BlogContract>(); | ||
|
||
[Inject] | ||
private IGetBlogsUseCase GetBlogsUseCase { get; set; } = null!; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await LoadBlogs(); | ||
|
||
_isReady = true; | ||
await base.OnInitializedAsync(); | ||
} | ||
|
||
private async Task LoadData(LoadDataArgs args) | ||
{ | ||
var skip = args.Skip ?? 0; | ||
var top = args.Top ?? 0; | ||
|
||
PagePosition = skip / top; | ||
|
||
await LoadBlogs(); | ||
} | ||
|
||
private async Task LoadBlogs() | ||
{ | ||
var result = await GetBlogsUseCase.GetBlogsAsync(PagePosition); | ||
|
||
_blogs = result.Blogs; | ||
_totalRecords = result.Count; | ||
} | ||
} |
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