Browse Source

Blogging appservices refactor

pull/751/head
Yunus Emre Kalkan 7 years ago
parent
commit
29aa7cd123
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/Dtos/GetPopularTagsInput.cs
  3. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs
  4. 8
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs
  5. 4
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs
  6. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
  7. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs
  8. 3
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs
  9. 2
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs

2
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<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input);
Task<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(Guid postId);
Task<CommentWithDetailsDto> CreateAsync(CreateCommentDto input);

2
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; }
}
}

2
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<List<TagDto>> GetPopularTags(GetPopularTagsInput input);
Task<List<TagDto>> GetPopularTags(Guid blogId, GetPopularTagsInput input);
}
}

8
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs

@ -26,9 +26,9 @@ namespace Volo.Blogging.Comments
UserLookupService = userLookupService;
}
public async Task<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input)
public async Task<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(Guid postId)
{
var comments = await GetListOfPostAsync(input);
var comments = await GetListOfPostAsync(postId);
var userDictionary = new Dictionary<Guid, BlogUserDto>();
foreach (var commentDto in comments)
@ -73,9 +73,9 @@ namespace Volo.Blogging.Comments
return hierarchicalComments;
}
private async Task<List<CommentWithDetailsDto>> GetListOfPostAsync(GetCommentListOfPostAsync input)
private async Task<List<CommentWithDetailsDto>> GetListOfPostAsync(Guid postId)
{
var comments = await _commentRepository.GetListOfPostAsync(input.PostId);
var comments = await _commentRepository.GetListOfPostAsync(postId);
return new List<CommentWithDetailsDto>(
ObjectMapper.Map<List<Comment>, List<CommentWithDetailsDto>>(comments));

4
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs

@ -22,9 +22,9 @@ namespace Volo.Blogging.Tagging
_tagRepository = tagRepository;
}
public async Task<List<TagDto>> GetPopularTags(GetPopularTagsInput input)
public async Task<List<TagDto>> 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();

2
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();
}

2
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}));
}
}
}

3
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);
}

2
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);
}

Loading…
Cancel
Save