Browse Source

blog module refactor

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
3292847bde
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs
  3. 9
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs
  4. 27
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs

@ -5,7 +5,7 @@ namespace Volo.Blogging.Comments.Dtos
{ {
public class CommentDto : FullAuditedEntityDto<Guid> public class CommentDto : FullAuditedEntityDto<Guid>
{ {
public Guid RepliedCommentId { get; set; } public Guid? RepliedCommentId { get; set; }
public string Text { get; set; } public string Text { get; set; }
} }

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs

@ -8,8 +8,6 @@ namespace Volo.Blogging.Comments
{ {
public interface ICommentAppService : IApplicationService public interface ICommentAppService : IApplicationService
{ {
Task<List<CommentDto>> GetListOfPostAsync(GetCommentListOfPostAsync input);
Task<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input); Task<List<CommentWithRepliesDto>> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input);
Task<CommentDto> CreateAsync(CreateCommentDto input); Task<CommentDto> CreateAsync(CreateCommentDto input);

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

@ -9,7 +9,7 @@ using Volo.Blogging.Comments.Dtos;
namespace Volo.Blogging.Comments namespace Volo.Blogging.Comments
{ {
// [Authorize(BloggingPermissions.Comments.Default)] // [Authorize(BloggingPermissions.Comments.Default)]
public class CommentAppService : ApplicationService, ICommentAppService public class CommentAppService : ApplicationService, ICommentAppService
{ {
private readonly ICommentRepository _commentRepository; private readonly ICommentRepository _commentRepository;
@ -42,15 +42,10 @@ namespace Volo.Blogging.Comments
hierarchicalComments = hierarchicalComments.OrderByDescending(c => c.Comment.CreationTime).ToList(); hierarchicalComments = hierarchicalComments.OrderByDescending(c => c.Comment.CreationTime).ToList();
foreach (var hierarchicalComment in hierarchicalComments)
{
hierarchicalComment.Replies = hierarchicalComment.Replies.OrderBy(c => c.CreationTime).ToList();
}
return hierarchicalComments; return hierarchicalComments;
} }
public async Task<List<CommentDto>> GetListOfPostAsync(GetCommentListOfPostAsync input) private async Task<List<CommentDto>> GetListOfPostAsync(GetCommentListOfPostAsync input)
{ {
var comments = await _commentRepository.GetListOfPostAsync(input.PostId); var comments = await _commentRepository.GetListOfPostAsync(input.PostId);

27
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -41,11 +41,7 @@ namespace Volo.Blogging.Posts
foreach (var postDto in postDtos) foreach (var postDto in postDtos)
{ {
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); postDto.Tags = await GetTagsOfPost(postDto);
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
postDto.Tags = ObjectMapper.Map<List<Tag>, List<TagDto>>(tags);
postDto.CommentCount = (await _commentRepository.GetListAsync()).Count(p => p.PostId == postDto.Id); postDto.CommentCount = (await _commentRepository.GetListAsync()).Count(p => p.PostId == postDto.Id);
} }
@ -67,11 +63,7 @@ namespace Volo.Blogging.Posts
var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post); var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post);
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); postDto.Tags = await GetTagsOfPost(postDto);
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
postDto.Tags = ObjectMapper.Map<List<Tag>, List<TagDto>>(tags);
return postDto; return postDto;
} }
@ -82,11 +74,7 @@ namespace Volo.Blogging.Posts
var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post); var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post);
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); postDto.Tags = await GetTagsOfPost(postDto);
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
postDto.Tags = ObjectMapper.Map<List<Tag>, List<TagDto>>(tags);
return postDto; return postDto;
} }
@ -162,6 +150,15 @@ namespace Volo.Blogging.Posts
} }
private async Task<List<TagDto>> GetTagsOfPost(PostWithDetailsDto postDto)
{
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id);
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
return ObjectMapper.Map<List<Tag>, List<TagDto>>(tags);
}
private List<string> SplitTags(string tags) private List<string> SplitTags(string tags)
{ {
if (tags.IsNullOrWhiteSpace()) if (tags.IsNullOrWhiteSpace())

Loading…
Cancel
Save