From 29aa7cd123c088d3e405beb473422d55db0c8598 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 22 Jan 2019 13:33:01 +0300 Subject: [PATCH] Blogging appservices refactor --- .../Volo/Blogging/Comments/ICommentAppService.cs | 2 +- .../Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs | 2 -- .../Volo/Blogging/Tagging/ITagAppService.cs | 2 +- .../Volo/Blogging/Comments/CommentAppService.cs | 8 ++++---- .../Volo/Blogging/Tagging/TagAppService.cs | 4 ++-- .../Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs | 2 +- .../Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs | 2 +- .../Volo/Blogging/CommentAppService_Tests.cs | 3 +-- .../Volo/Blogging/TagAppService_Tests.cs | 2 +- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs index d91b66ae80..15ef72d8b3 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs @@ -8,7 +8,7 @@ namespace Volo.Blogging.Comments { public interface ICommentAppService : IApplicationService { - Task> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input); + Task> GetHierarchicalListOfPostAsync(Guid postId); Task CreateAsync(CreateCommentDto input); diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs index 85cd1e746e..b4c0a07eb5 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs @@ -7,7 +7,5 @@ namespace Volo.Blogging.Tagging.Dtos public int ResultCount { get; set; } = 10; public int? MinimumPostCount { get; set; } - - public Guid BlogId { get; set; } } } \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs index abc4c9daba..8ee283dbcd 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs @@ -8,7 +8,7 @@ namespace Volo.Blogging.Tagging { public interface ITagAppService : IApplicationService { - Task> GetPopularTags(GetPopularTagsInput input); + Task> GetPopularTags(Guid blogId, GetPopularTagsInput input); } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 2598a823f3..32b31da23a 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -26,9 +26,9 @@ namespace Volo.Blogging.Comments UserLookupService = userLookupService; } - public async Task> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input) + public async Task> GetHierarchicalListOfPostAsync(Guid postId) { - var comments = await GetListOfPostAsync(input); + var comments = await GetListOfPostAsync(postId); var userDictionary = new Dictionary(); foreach (var commentDto in comments) @@ -73,9 +73,9 @@ namespace Volo.Blogging.Comments return hierarchicalComments; } - private async Task> GetListOfPostAsync(GetCommentListOfPostAsync input) + private async Task> GetListOfPostAsync(Guid postId) { - var comments = await _commentRepository.GetListOfPostAsync(input.PostId); + var comments = await _commentRepository.GetListOfPostAsync(postId); return new List( ObjectMapper.Map, List>(comments)); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs index 11b98f4d95..473a8698df 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs @@ -22,9 +22,9 @@ namespace Volo.Blogging.Tagging _tagRepository = tagRepository; } - public async Task> GetPopularTags(GetPopularTagsInput input) + public async Task> GetPopularTags(Guid blogId, GetPopularTagsInput input) { - var postTags = (await _tagRepository.GetListAsync(input.BlogId)).OrderByDescending(t=>t.UsageCount) + var postTags = (await _tagRepository.GetListAsync(blogId)).OrderByDescending(t=>t.UsageCount) .WhereIf(input.MinimumPostCount != null, t=>t.UsageCount >= input.MinimumPostCount) .Take(input.ResultCount).ToList(); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs index 953c3aa8a1..83edb281b0 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs @@ -70,7 +70,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl }); - CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(new GetCommentListOfPostAsync() { PostId = Post.Id }); + CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id); CountComments(); } 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 c9cfc21227..8702171d9f 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 @@ -39,7 +39,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Posts = (await _postAppService.GetListByBlogIdAndTagName(Blog.Id, TagName)).Items; - PopularTags = (await _tagAppService.GetPopularTags(new GetPopularTagsInput {BlogId = Blog.Id, ResultCount = 10, MinimumPostCount = 2})); + PopularTags = (await _tagAppService.GetPopularTags(Blog.Id, new GetPopularTagsInput {ResultCount = 10, MinimumPostCount = 2})); } } } \ No newline at end of file diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs index d9dcdf41c5..6870bee509 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs @@ -33,8 +33,7 @@ namespace Volo.Blogging await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, null, "qweasd")); var comments = - await _commentAppService.GetHierarchicalListOfPostAsync( - new GetCommentListOfPostAsync() { PostId = post.Id }); + await _commentAppService.GetHierarchicalListOfPostAsync(post.Id); comments.Count.ShouldBeGreaterThan(2); } diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs index ca8e2e8531..d152eead55 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs @@ -23,7 +23,7 @@ namespace Volo.Blogging [Fact] public async Task Should_Get_Popular_Tags() { - var tags = await _tagAppService.GetPopularTags(new GetPopularTagsInput() { BlogId = _bloggingTestData.Blog1Id, ResultCount = 5, MinimumPostCount = 0 }); + var tags = await _tagAppService.GetPopularTags(_bloggingTestData.Blog1Id, new GetPopularTagsInput() {ResultCount = 5, MinimumPostCount = 0 }); tags.Count.ShouldBeGreaterThan(0); }