Skip to content

Commit dc00334

Browse files
committed
get posts on the home page
1 parent b524acc commit dc00334

File tree

26 files changed

+296
-146
lines changed

26 files changed

+296
-146
lines changed

src/BlogCore.ComponentsLibrary/BadminLteCard.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="card">
1+
<div class="card card-primary card-outline">
22
<div class="card-header">
33
@CardHeader
44
</div>

src/BlogCore.Hosts.Tests/MessageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BlogCore.Shared.v1.Blog;
2+
using BlogCore.Shared.v1.Blogs.Validators;
23
using BlogCore.Shared.v1.ValidationModel;
3-
using BlogCore.Shared.v1.Validators;
44
using Google.Protobuf;
55
using System;
66
using System.Threading.Tasks;

src/BlogCore.Hosts.Web.Client/Pages/Settings.razor renamed to src/BlogCore.Hosts.Web.Client/Pages/BlogSettings.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/settings"
1+
@page "/blog-settings"
22
@attribute [Authorize]
33

44
@code {

src/BlogCore.Hosts.Web.Client/Pages/Blogs.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@page "/blogs"
22
@page "/blogs/{Page:int}"
33
@attribute [Authorize]
4-
@inject BlogService BlogService
54
@inject IJSRuntime JS
5+
@inject BlogService BlogService
66

77
<div class="container-fluid">
88
<BadminLteCard>
99
<CardHeader>
1010
<NavLink href="create-blog" class="btn btn-primary btn-sm">New</NavLink>
11+
<NavLink href="blog-settings" class="btn btn-info btn-sm">Settings</NavLink>
1112
<button class="btn btn-danger btn-sm">Delete Selected</button>
1213
</CardHeader>
1314
<CardBody>
Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@page "/"
2+
@page "/{Page:int}"
23
@layout NoLayout
4+
@inject PostService PostService
35

46
<div class="jumbotron jumbotron-fluid">
57
<div class="container">
@@ -12,62 +14,35 @@
1214
<div class="container">
1315
<div class="row">
1416
<div class="col-md-12">
15-
<!-- Post -->
16-
<div class="post">
17-
<div class="user-block">
18-
<h1>
19-
<NavLink href="/post/1">This is post 1</NavLink>
20-
</h1>
21-
<div>Created at 7:30 PM today</div>
17+
@foreach (var post in Posts)
18+
{
19+
<!-- Post -->
20+
<div class="post">
21+
<div class="user-block">
22+
<h1>
23+
<a href="/post/@post.Id">@post.Title</a>
24+
</h1>
25+
<div>Created at @post.CreatedAt</div>
26+
</div>
27+
<!-- /.user-block -->
28+
<p>
29+
@post.Excerpt...
30+
</p>
31+
<p>
32+
@RenderTag(post.Id)
33+
</p>
34+
<p>
35+
<a href="#" class="link-black text-sm mr-2"><i class="fas fa-share mr-1"></i> Share</a>
36+
<a href="#" class="link-black text-sm"><i class="far fa-thumbs-up mr-1"></i> Like</a>
37+
<span class="float-right">
38+
<NavLink href="#" class="link-black text-sm">
39+
<i class="far fa-comments mr-1"></i> Comments (5)
40+
</NavLink>
41+
</span>
42+
</p>
2243
</div>
23-
<!-- /.user-block -->
24-
<p>
25-
Lorem ipsum represents a long-held tradition for designers,
26-
typographers and the like. Some people hate it and argue for
27-
its demise, but others ignore the hate as they create awesome
28-
tools to help create filler text for everyone from bacon lovers
29-
to Charlie Sheen fans...
30-
</p>
31-
32-
<p>
33-
<a href="#" class="link-black text-sm mr-2"><i class="fas fa-share mr-1"></i> Share</a>
34-
<a href="#" class="link-black text-sm"><i class="far fa-thumbs-up mr-1"></i> Like</a>
35-
<span class="float-right">
36-
<NavLink href="#" class="link-black text-sm">
37-
<i class="far fa-comments mr-1"></i> Comments (5)
38-
</NavLink>
39-
</span>
40-
</p>
41-
</div>
42-
<!-- /.post -->
43-
<!-- Post -->
44-
<div class="post clearfix">
45-
<div class="user-block">
46-
<h1>
47-
<NavLink href="/post/2">This is post 2</NavLink>
48-
</h1>
49-
<div>Created at 3 days ago</div>
50-
</div>
51-
<!-- /.user-block -->
52-
<p>
53-
Lorem ipsum represents a long-held tradition for designers,
54-
typographers and the like. Some people hate it and argue for
55-
its demise, but others ignore the hate as they create awesome
56-
tools to help create filler text for everyone from bacon lovers
57-
to Charlie Sheen fans...
58-
</p>
59-
60-
<p>
61-
<a href="#" class="link-black text-sm mr-2"><i class="fas fa-share mr-1"></i> Share</a>
62-
<a href="#" class="link-black text-sm"><i class="far fa-thumbs-up mr-1"></i> Like</a>
63-
<span class="float-right">
64-
<NavLink href="#" class="link-black text-sm">
65-
<i class="far fa-comments mr-1"></i> Comments (5)
66-
</NavLink>
67-
</span>
68-
</p>
69-
</div>
70-
<!-- /.post -->
44+
<!-- /.post -->
45+
}
7146
</div>
7247
</div>
7348
</div>
@@ -83,4 +58,27 @@
8358
</div>
8459

8560
@code {
61+
[Parameter] int Page { get; set; } = 1;
62+
63+
List<PostDto> Posts = new List<PostDto>();
64+
MapField<string, PostTagsDto> PostTags = new MapField<string, PostTagsDto>();
65+
66+
protected override async Task OnInitAsync()
67+
{
68+
var resultModel = await PostService.GetPostsByBlog(Guid.NewGuid(), Page);
69+
Posts = resultModel.Data.Posts.ToList();
70+
PostTags = resultModel.Data.TagFragment;
71+
}
72+
73+
MarkupString RenderTag(string postId)
74+
{
75+
var result = PostTags
76+
.Where(x => x.Key == postId)
77+
.Select(x => x.Value)
78+
.SelectMany(x => x.Tags)
79+
.Select(x => x?.Name)
80+
.Aggregate("", (r, x) => r + string.Format("<span class=\"badge badge-info\">{0}</span>", x));
81+
82+
return (MarkupString)result;
83+
}
8684
}

src/BlogCore.Hosts.Web.Client/Pages/PublicPost.razor

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/post/{PostId:int}"
1+
@page "/post/{PostId:guid}"
22
@layout NoLayout
33

44
<div class="jumbotron jumbotron-fluid">
@@ -93,6 +93,5 @@
9393
</div>
9494

9595
@code {
96-
[Parameter]
97-
int PostId { get; set; } = 1;
96+
[Parameter] Guid PostId { get; set; }
9897
}

src/BlogCore.Hosts.Web.Client/Services/BlogService.cs renamed to src/BlogCore.Hosts.Web.Client/Services/Impl/BlogService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Threading.Tasks;
77

8-
namespace BlogCore.Hosts.Web.Client.Services
8+
namespace BlogCore.Hosts.Web.Client.Services.Impl
99
{
1010
public class BlogService : ServiceBase
1111
{
@@ -16,19 +16,19 @@ public BlogService(IServiceProvider serviceProvider) : base(serviceProvider)
1616
public async Task<ProtoResultModel<PaginatedItemResponse>> GetBlogs(int page)
1717
{
1818
var httpClient = await SecureHttpClientAsync();
19-
return await httpClient.GetProtoAsync<PaginatedItemResponse>($"api/blogs?page={page}");
19+
return await httpClient.GetProtoAsync<PaginatedItemResponse>($"api/@blogs?page={page}");
2020
}
2121

2222
public async Task<ProtoResultModel<RetrieveBlogResponse>> GetBlogById(Guid blogId)
2323
{
2424
var httpClient = await SecureHttpClientAsync();
25-
return await httpClient.GetProtoAsync<RetrieveBlogResponse>($"api/blogs/{blogId}");
25+
return await httpClient.GetProtoAsync<RetrieveBlogResponse>($"api/@blogs/{blogId}");
2626
}
2727

2828
public async Task<ProtoResultModel<CreateBlogResponse>> CreateBlog(CreateBlogRequest model)
2929
{
3030
var httpClient = await SecureHttpClientAsync();
31-
return await httpClient.PostProtoAsync<CreateBlogResponse>($"api/blogs", model);
31+
return await httpClient.PostProtoAsync<CreateBlogResponse>($"api/@blogs", model);
3232
}
3333
}
3434
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using BlogCore.Shared;
2+
using BlogCore.Shared.v1;
3+
using BlogCore.Shared.v1.Post;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
namespace BlogCore.Hosts.Web.Client.Services.Impl
8+
{
9+
public class PostService : ServiceBase
10+
{
11+
public PostService(IServiceProvider serviceProvider) : base(serviceProvider)
12+
{
13+
}
14+
15+
public async Task<ProtoResultModel<GetPostsByBlogResponse>> GetPostsByBlog(Guid blogId, int page)
16+
{
17+
return await HttpClient.GetProtoAsync<GetPostsByBlogResponse>($"api/posts/{blogId}/posts?page={page}");
18+
}
19+
}
20+
}

src/BlogCore.Hosts.Web.Client/Shared/NavMenu.razor

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
</p>
2828
</NavLink>
2929
</li>
30-
<li class="nav-item">
31-
<NavLink class="nav-link" href="settings">
32-
<i class="nav-icon fas fa-cogs"></i>
33-
<p>
34-
Settings
35-
</p>
36-
</NavLink>
37-
</li>
3830
<li class="nav-item">
3931
<NavLink class="nav-link" href="/" Match="NavLinkMatch.All">
4032
<i class="nav-icon fas fa-copy"></i>

src/BlogCore.Hosts.Web.Client/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BlogCore.Hosts.Web.Client.Services;
2+
using BlogCore.Hosts.Web.Client.Services.Impl;
23
using Microsoft.AspNetCore.Components;
34
using Microsoft.AspNetCore.Components.Builder;
45
using Microsoft.Extensions.DependencyInjection;
@@ -16,6 +17,7 @@ public void ConfigureServices(IServiceCollection services)
1617
// services and state
1718
services.AddScoped<AppState>();
1819
services.AddScoped<BlogService>();
20+
services.AddScoped<PostService>();
1921
}
2022

2123
public void Configure(IComponentsApplicationBuilder app)

0 commit comments

Comments
 (0)