|
|
@ -24,15 +24,13 @@ namespace Volo.Blogging.Posts
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IPostRepository _postRepository;
|
|
|
|
private readonly IPostRepository _postRepository;
|
|
|
|
private readonly ITagRepository _tagRepository;
|
|
|
|
private readonly ITagRepository _tagRepository;
|
|
|
|
private readonly IPostTagRepository _postTagRepository;
|
|
|
|
|
|
|
|
private readonly ICommentRepository _commentRepository;
|
|
|
|
private readonly ICommentRepository _commentRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public PostAppService(IPostRepository postRepository, ITagRepository tagRepository, IPostTagRepository postTagRepository, ICommentRepository commentRepository, IBlogUserLookupService userLookupService)
|
|
|
|
public PostAppService(IPostRepository postRepository, ITagRepository tagRepository, ICommentRepository commentRepository, IBlogUserLookupService userLookupService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UserLookupService = userLookupService;
|
|
|
|
UserLookupService = userLookupService;
|
|
|
|
_postRepository = postRepository;
|
|
|
|
_postRepository = postRepository;
|
|
|
|
_tagRepository = tagRepository;
|
|
|
|
_tagRepository = tagRepository;
|
|
|
|
_postTagRepository = postTagRepository;
|
|
|
|
|
|
|
|
_commentRepository = commentRepository;
|
|
|
|
_commentRepository = commentRepository;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -85,10 +83,11 @@ namespace Volo.Blogging.Posts
|
|
|
|
private async Task<List<PostWithDetailsDto>> FilterPostsByTag(List<PostWithDetailsDto> allPostDtos, Tag tag)
|
|
|
|
private async Task<List<PostWithDetailsDto>> FilterPostsByTag(List<PostWithDetailsDto> allPostDtos, Tag tag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var filteredPostDtos = new List<PostWithDetailsDto>();
|
|
|
|
var filteredPostDtos = new List<PostWithDetailsDto>();
|
|
|
|
|
|
|
|
var posts = await _postRepository.GetListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var postDto in allPostDtos)
|
|
|
|
foreach (var postDto in allPostDtos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (await _postTagRepository.FindByTagIdAndPostIdAsync(postDto.Id, tag.Id) == null)
|
|
|
|
if (!postDto.Tags.Any(p=> p.Id == tag.Id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,7 +144,6 @@ namespace Volo.Blogging.Posts
|
|
|
|
|
|
|
|
|
|
|
|
var tags = await GetTagsOfPost(id);
|
|
|
|
var tags = await GetTagsOfPost(id);
|
|
|
|
_tagRepository.DecreaseUsageCountOfTags(tags.Select(t => t.Id).ToList());
|
|
|
|
_tagRepository.DecreaseUsageCountOfTags(tags.Select(t => t.Id).ToList());
|
|
|
|
_postTagRepository.DeleteOfPost(id);
|
|
|
|
|
|
|
|
await _commentRepository.DeleteOfPost(id);
|
|
|
|
await _commentRepository.DeleteOfPost(id);
|
|
|
|
|
|
|
|
|
|
|
|
await _postRepository.DeleteAsync(id);
|
|
|
|
await _postRepository.DeleteAsync(id);
|
|
|
@ -210,7 +208,6 @@ namespace Volo.Blogging.Posts
|
|
|
|
|
|
|
|
|
|
|
|
private async Task SaveTags(List<String> newTags, Post post)
|
|
|
|
private async Task SaveTags(List<String> newTags, Post post)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
await RemoveOldTags(newTags, post);
|
|
|
|
await RemoveOldTags(newTags, post);
|
|
|
|
|
|
|
|
|
|
|
|
await AddNewTags(newTags, post);
|
|
|
|
await AddNewTags(newTags, post);
|
|
|
@ -218,9 +215,7 @@ namespace Volo.Blogging.Posts
|
|
|
|
|
|
|
|
|
|
|
|
private async Task RemoveOldTags(List<string> newTags, Post post)
|
|
|
|
private async Task RemoveOldTags(List<string> newTags, Post post)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var oldTags = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == post.Id).ToList();
|
|
|
|
foreach (var oldTag in post.Tags)
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var oldTag in oldTags)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tag = await _tagRepository.GetAsync(oldTag.TagId);
|
|
|
|
var tag = await _tagRepository.GetAsync(oldTag.TagId);
|
|
|
|
|
|
|
|
|
|
|
@ -228,7 +223,7 @@ namespace Volo.Blogging.Posts
|
|
|
|
|
|
|
|
|
|
|
|
if (oldTagNameInNewTags == null)
|
|
|
|
if (oldTagNameInNewTags == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await _postTagRepository.DeleteAsync(oldTag);
|
|
|
|
post.RemoveTag(oldTag.TagId);
|
|
|
|
|
|
|
|
|
|
|
|
tag.DecreaseUsageCount();
|
|
|
|
tag.DecreaseUsageCount();
|
|
|
|
await _tagRepository.UpdateAsync(tag);
|
|
|
|
await _tagRepository.UpdateAsync(tag);
|
|
|
@ -256,15 +251,14 @@ namespace Volo.Blogging.Posts
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tag.IncreaseUsageCount();
|
|
|
|
tag.IncreaseUsageCount();
|
|
|
|
tag = await _tagRepository.UpdateAsync(tag);
|
|
|
|
tag = await _tagRepository.UpdateAsync(tag);
|
|
|
|
|
|
|
|
post.AddTag(tag.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await _postTagRepository.InsertAsync(new PostTag(post.Id, tag.Id));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<TagDto>> GetTagsOfPost(Guid id)
|
|
|
|
private async Task<List<TagDto>> GetTagsOfPost(Guid id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == id);
|
|
|
|
var tagIds = (await _postRepository.GetAsync(id)).Tags;
|
|
|
|
|
|
|
|
|
|
|
|
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
|
|
|
|
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));
|
|
|
|
|
|
|
|
|
|
|
|