Skip to content

Commit

Permalink
Start with Admin Blog details
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Oct 19, 2023
1 parent 64ea220 commit f629bd0
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 3 deletions.
20 changes: 20 additions & 0 deletions MadWorld/MadWorld.Frontend.Application/Blogs/GetBlogUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using MadWorld.Frontend.Domain.Blogs;
using MadWorld.Shared.Contracts.Anonymous.Blog;

namespace MadWorld.Frontend.Application.Blogs;

public class GetBlogUseCase : IGetBlogUseCase
{
private readonly IBlogService _service;

public GetBlogUseCase(IBlogService service)
{
_service = service;
}

public async Task<BlogDetailContract> GetBlog(string id)
{
var response = await _service.GetBlog(id);
return response.Blog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static IServiceCollection AddApplication(this IServiceCollection services
services.AddScoped<IGetAccountUseCase, GetAccountUseCase>();
services.AddScoped<IGetAccountsUseCase, GetAccountsUseCase>();
services.AddScoped<IGetBlogsUseCase, GetBlogsUseCase>();
services.AddScoped<IGetBlogUseCase, GetBlogUseCase>();
services.AddScoped<IGetCurriculumVitaeUseCase, GetCurriculumVitaeUseCase>();
services.AddScoped<IPatchAccountUseCase, PatchAccountUseCase>();
services.AddScoped<IPatchCurriculumVitaeUseCase, PatchCurriculumVitaeUseCase>();
Expand Down
1 change: 1 addition & 0 deletions MadWorld/MadWorld.Frontend.Domain/Blogs/IBlogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace MadWorld.Frontend.Domain.Blogs;
public interface IBlogService
{
Task<GetBlogsResponse> GetBlogs(int pageNumber);
Task<GetBlogResponse> GetBlog(string id);
}
8 changes: 8 additions & 0 deletions MadWorld/MadWorld.Frontend.Domain/Blogs/IGetBlogUseCase.cs
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 IGetBlogUseCase
{
Task<BlogDetailContract> GetBlog(string id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace MadWorld.Frontend.Infrastructure.BlogService;

public class BlogService : IBlogService
{
private const string Endpoint = "Blogs";
private const string EndpointPlural = "Blogs";
private const string EndpointSingular = "Blog";

private readonly HttpClient _client;

Expand All @@ -17,6 +18,11 @@ public BlogService(IHttpClientFactory clientFactory)
}
public async Task<GetBlogsResponse> GetBlogs(int pageNumber)
{
return await _client.GetFromJsonAsync<GetBlogsResponse>($"{Endpoint}/{pageNumber}") ?? new GetBlogsResponse(0, Array.Empty<BlogContract>());
return await _client.GetFromJsonAsync<GetBlogsResponse>($"{EndpointPlural}/{pageNumber}") ?? new GetBlogsResponse(0, Array.Empty<BlogContract>());
}

public async Task<GetBlogResponse> GetBlog(string id)
{
return await _client.GetFromJsonAsync<GetBlogResponse>($"{EndpointSingular}/{id}") ?? new GetBlogResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/Blog/{Id?}"

@Blog.Title
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JetBrains.Annotations;
using MadWorld.Frontend.Domain.Blogs;
using MadWorld.Shared.Contracts.Anonymous.Blog;
using Microsoft.AspNetCore.Components;

namespace MadWorld.Frontend.UI.Admin.Pages.Blogs;

[UsedImplicitly]
public partial class BlogDetails
{
[Parameter]
public string Id { get; set; } = null!;
private BlogDetailContract Blog { get; set; } = new();

private bool IsNewBlog => string.IsNullOrWhiteSpace(Id);
private bool IsReady { get; set; }

[Inject]
private IGetBlogUseCase GetBlogUseCase { get; set; } = null!;

protected override async Task OnInitializedAsync()
{
if (!IsNewBlog)
{
Blog = await GetBlogUseCase.GetBlog(Id);
}

IsReady = true;
await base.OnInitializedAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<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">
TItem="BlogContract" ShowPagingSummary="true" PagingSummaryFormat="@pagingSummaryFormat"
RowClick="OpenBlogDetails">
<Columns>
<RadzenDataGridColumn TItem="BlogContract" Property="Title" Title="Title" />
<RadzenDataGridColumn TItem="BlogContract" Property="Created" Title="Created" />
</Columns>
</RadzenDataGrid>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public partial class BlogOverview

[Inject]
private IGetBlogsUseCase GetBlogsUseCase { get; set; } = null!;

[Inject]
private NavigationManager NavigationManager { get; set; } = null!;

protected override async Task OnInitializedAsync()
{
Expand All @@ -49,4 +52,9 @@ private async Task LoadBlogs()
_blogs = result.Blogs;
_totalRecords = result.Count;
}

private void OpenBlogDetails(DataGridRowMouseEventArgs<BlogContract> blog)
{
NavigationManager.NavigateTo($"/Blog/{blog.Data.Id}");
}
}

0 comments on commit f629bd0

Please sign in to comment.