From 83c506d2bcc0f5fd8793e93639f5dd707c6ecdec Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 11:43:02 +0300 Subject: [PATCH] Blog module tag page moved to index --- .../Volo/Blogging/Posts/IPostAppService.cs | 2 - .../Volo/Blogging/Posts/PostAppService.cs | 17 ++-- .../Volo.Blogging.Web/BloggingWebModule.cs | 1 - .../Pages/Blog/Posts/Detail.cshtml | 4 +- .../Pages/Blog/Posts/Index.cshtml | 6 +- .../Pages/Blog/Posts/Index.cshtml.cs | 5 +- .../Pages/Blog/Tags/Posts.cshtml | 93 ------------------- .../Pages/Blog/Tags/Posts.cshtml.cs | 34 ------- 8 files changed, 16 insertions(+), 146 deletions(-) delete mode 100644 modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml delete mode 100644 modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs index cc2da9521d..fc1e536b45 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs @@ -7,8 +7,6 @@ namespace Volo.Blogging.Posts { public interface IPostAppService : IApplicationService { - Task> GetListByBlogId(Guid id); - Task> GetListByBlogIdAndTagName(Guid blogId, string tagName); Task GetForReadingAsync(GetPostInput input); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 0df97fdd1e..f39f9f369e 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -32,7 +32,7 @@ namespace Volo.Blogging.Posts _commentRepository = commentRepository; } - public async Task> GetListByBlogId(Guid id) + public async Task> GetListByBlogIdAndTagName(Guid id, string tagName) { var posts = _postRepository.GetPostsByBlogId(id); @@ -50,16 +50,13 @@ namespace Volo.Blogging.Posts postDto.CommentCount = (await _commentRepository.GetListAsync()).Count(p => p.PostId == postDto.Id); } - return new ListResultDto(postDtos); - } - - public async Task> GetListByBlogIdAndTagName(Guid blogId, string tagName) - { - var all = (await GetListByBlogId(blogId)).Items; - - var tag = await _tagRepository.GetByNameAsync(tagName); + if (!tagName.IsNullOrWhiteSpace()) + { + var tag = await _tagRepository.GetByNameAsync(tagName); + postDtos = postDtos.Where(p => p.Tags.Any(t => t.Id == tag.Id)).ToList(); + } - return new ListResultDto(all.Where(p=>p.Tags.Any(t=>t.Id == tag.Id)).ToList()); + return new ListResultDto(postDtos); } public async Task GetForReadingAsync(GetPostInput input) diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs index 44f8b7cd8d..9ec9c04d94 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs @@ -61,7 +61,6 @@ namespace Volo.Blogging options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postUrl}"); options.Conventions.AddPageRoute("/Blog/Posts/Edit", "blog/{blogShortName}/posts/edit/{postId}"); options.Conventions.AddPageRoute("/Blog/Posts/New", "blog/{blogShortName}/posts/new"); - options.Conventions.AddPageRoute("/Blog/Tags/Posts", "blog/{blogShortName}/{tagName}/posts"); }); context.Services.AddAssemblyOf(); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 5ebfafc427..71843c16d9 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -30,7 +30,7 @@

@foreach (var tag in Model.Post.Tags) { - @tag.Name + @tag.Name }

@@ -94,7 +94,7 @@

@L["TagsInThisArticle"]
@foreach (var tag in Model.Post.Tags) { - @tag.Name + @tag.Name }
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml index 4726d9a1d4..3ce970e11b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml @@ -46,7 +46,7 @@

@foreach (var tag in post.Tags) { - @tag.Name + @tag.Name }

@@ -188,7 +188,7 @@

@foreach (var tag in post.Tags) { - @tag.Name + @tag.Name }

@@ -234,7 +234,7 @@ diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs index 9d6a9cb635..eb9b8b9574 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs @@ -18,6 +18,9 @@ namespace Volo.Blogging.Pages.Blog.Posts [BindProperty(SupportsGet = true)] public string BlogShortName { get; set; } + [BindProperty(SupportsGet = true)] + public string TagName { get; set; } + public IReadOnlyList Posts { get; set; } public IReadOnlyList PopularTags { get; set; } @@ -32,7 +35,7 @@ namespace Volo.Blogging.Pages.Blog.Posts public async Task OnGetAsync() { var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - Posts = (await _postAppService.GetListByBlogId(blog.Id)).Items; + Posts = (await _postAppService.GetListByBlogIdAndTagName(blog.Id, TagName)).Items; PopularTags = (await _tagAppService.GetPopularTags(new GetPopularTagsInput {ResultCount = 10})); } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml deleted file mode 100644 index ff643406b0..0000000000 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml +++ /dev/null @@ -1,93 +0,0 @@ -@page -@inherits Volo.Blogging.Pages.Blog.BloggingPage -@using Volo.Blogging.Pages.Blog.Tags -@model PostsModel -@{ -} - -@section scripts { - - - -} -@section styles { - - - -} - -
-
-
-
-
-
-

#@Model.TagName

-
-
-
- - @for (var index = 0; index < Model.Posts.Count; index++) - { - var post = Model.Posts[index]; - var oddPost = index % 2 == 1; - -
-
-
-
- - - - -
-
-
-

- @foreach (var tag in post.Tags) - { - @tag.Name - } -

-

- @post.Title -

-

- @(post.Content == null ? "" : (post.Content.Length > 250 ? post.Content.Substring(0, 150) : post.Content))... -

-
- -
-
-
-
- } - -
- -
-
\ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs deleted file mode 100644 index bb040e021b..0000000000 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Volo.Blogging.Blogs; -using Volo.Blogging.Posts; - -namespace Volo.Blogging.Pages.Blog.Tags -{ - public class PostsModel : PageModel - { - private readonly IPostAppService _postAppService; - private readonly IBlogAppService _blogAppService; - - [BindProperty(SupportsGet = true)] - public string BlogShortName { get; set; } - - [BindProperty(SupportsGet = true)] - public string TagName { get; set; } - - public IReadOnlyList Posts { get; set; } - - public PostsModel(IPostAppService postAppService, IBlogAppService blogAppService) - { - _postAppService = postAppService; - _blogAppService = blogAppService; - } - - public async void OnGetAsync() - { - var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - Posts = (await _postAppService.GetListByBlogIdAndTagName(blog.Id, TagName)).Items; - } - } -} \ No newline at end of file