Browse Source

Blogging: Update service injection property types as protected

pull/11520/head
Engincan VESKE 5 years ago
parent
commit
0c0e07261c
  1. 10
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs
  2. 28
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs
  3. 8
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAuthorizationHandler.cs
  4. 64
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  5. 8
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs
  6. 6
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs

10
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs

@ -11,16 +11,16 @@ namespace Volo.Blogging.Blogs
{
public class BlogAppService : BloggingAppServiceBase, IBlogAppService
{
private readonly IBlogRepository _blogRepository;
protected IBlogRepository BlogRepository { get; }
public BlogAppService(IBlogRepository blogRepository)
{
_blogRepository = blogRepository;
BlogRepository = blogRepository;
}
public async Task<ListResultDto<BlogDto>> GetListAsync()
{
var blogs = await _blogRepository.GetListAsync();
var blogs = await BlogRepository.GetListAsync();
return new ListResultDto<BlogDto>(
ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs)
@ -31,7 +31,7 @@ namespace Volo.Blogging.Blogs
{
Check.NotNullOrWhiteSpace(shortName, nameof(shortName));
var blog = await _blogRepository.FindByShortNameAsync(shortName);
var blog = await BlogRepository.FindByShortNameAsync(shortName);
if (blog == null)
{
@ -43,7 +43,7 @@ namespace Volo.Blogging.Blogs
public async Task<BlogDto> GetAsync(Guid id)
{
var blog = await _blogRepository.GetAsync(id);
var blog = await BlogRepository.GetAsync(id);
return ObjectMapper.Map<Blog, BlogDto>(blog);
}

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

@ -13,15 +13,13 @@ namespace Volo.Blogging.Comments
{
public class CommentAppService : BloggingAppServiceBase, ICommentAppService
{
protected IBlogUserLookupService UserLookupService;
protected IBlogUserLookupService UserLookupService { get; }
private readonly ICommentRepository _commentRepository;
private readonly IGuidGenerator _guidGenerator;
protected ICommentRepository CommentRepository { get; }
public CommentAppService(ICommentRepository commentRepository, IGuidGenerator guidGenerator, IBlogUserLookupService userLookupService)
public CommentAppService(ICommentRepository commentRepository, IBlogUserLookupService userLookupService)
{
_commentRepository = commentRepository;
_guidGenerator = guidGenerator;
CommentRepository = commentRepository;
UserLookupService = userLookupService;
}
@ -74,7 +72,7 @@ namespace Volo.Blogging.Comments
private async Task<List<CommentWithDetailsDto>> GetListOfPostAsync(Guid postId)
{
var comments = await _commentRepository.GetListOfPostAsync(postId);
var comments = await CommentRepository.GetListOfPostAsync(postId);
return new List<CommentWithDetailsDto>(
ObjectMapper.Map<List<Comment>, List<CommentWithDetailsDto>>(comments));
@ -83,9 +81,9 @@ namespace Volo.Blogging.Comments
[Authorize]
public async Task<CommentWithDetailsDto> CreateAsync(CreateCommentDto input)
{
var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text);
var comment = new Comment(GuidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text);
comment = await _commentRepository.InsertAsync(comment);
comment = await CommentRepository.InsertAsync(comment);
await CurrentUnitOfWork.SaveChangesAsync();
@ -95,14 +93,14 @@ namespace Volo.Blogging.Comments
[Authorize]
public async Task<CommentWithDetailsDto> UpdateAsync(Guid id, UpdateCommentDto input)
{
var comment = await _commentRepository.GetAsync(id);
var comment = await CommentRepository.GetAsync(id);
await AuthorizationService.CheckAsync(comment, CommonOperations.Update);
comment.SetText(input.Text);
comment.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
comment = await _commentRepository.UpdateAsync(comment);
comment = await CommentRepository.UpdateAsync(comment);
return ObjectMapper.Map<Comment, CommentWithDetailsDto>(comment);
}
@ -110,17 +108,17 @@ namespace Volo.Blogging.Comments
[Authorize]
public async Task DeleteAsync(Guid id)
{
var comment = await _commentRepository.GetAsync(id);
var comment = await CommentRepository.GetAsync(id);
await AuthorizationService.CheckAsync(comment, CommonOperations.Delete);
await _commentRepository.DeleteAsync(id);
await CommentRepository.DeleteAsync(id);
var replies = await _commentRepository.GetRepliesOfComment(id);
var replies = await CommentRepository.GetRepliesOfComment(id);
foreach (var reply in replies)
{
await _commentRepository.DeleteAsync(reply.Id);
await CommentRepository.DeleteAsync(reply.Id);
}
}
}

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

@ -8,11 +8,11 @@ namespace Volo.Blogging.Comments
{
public class CommentAuthorizationHandler : AuthorizationHandler<OperationAuthorizationRequirement, Comment>
{
private readonly IPermissionChecker _permissionChecker;
protected IPermissionChecker PermissionChecker { get; }
public CommentAuthorizationHandler(IPermissionChecker permissionChecker)
{
_permissionChecker = permissionChecker;
PermissionChecker = permissionChecker;
}
protected async override Task HandleRequirementAsync(
@ -40,7 +40,7 @@ namespace Volo.Blogging.Comments
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete))
if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete))
{
return true;
}
@ -55,7 +55,7 @@ namespace Volo.Blogging.Comments
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Update))
if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Update))
{
return true;
}

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

@ -19,11 +19,11 @@ namespace Volo.Blogging.Posts
{
protected IBlogUserLookupService UserLookupService { get; }
private readonly IPostRepository _postRepository;
private readonly ITagRepository _tagRepository;
private readonly ICommentRepository _commentRepository;
private readonly IDistributedCache<List<PostCacheItem>> _postsCache;
private readonly ILocalEventBus _localEventBus;
protected IPostRepository PostRepository { get; }
protected ITagRepository TagRepository { get; }
protected ICommentRepository CommentRepository { get; }
protected IDistributedCache<List<PostCacheItem>> PostsCache { get; }
protected ILocalEventBus LocalEventBus { get; }
public PostAppService(
IPostRepository postRepository,
@ -35,17 +35,17 @@ namespace Volo.Blogging.Posts
)
{
UserLookupService = userLookupService;
_postRepository = postRepository;
_tagRepository = tagRepository;
_commentRepository = commentRepository;
_postsCache = postsCache;
_localEventBus = localEventBus;
PostRepository = postRepository;
TagRepository = tagRepository;
CommentRepository = commentRepository;
PostsCache = postsCache;
LocalEventBus = localEventBus;
}
public async Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagNameAsync(Guid id, string tagName)
{
var posts = await _postRepository.GetPostsByBlogId(id);
var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName);
var posts = await PostRepository.GetPostsByBlogId(id);
var tag = tagName.IsNullOrWhiteSpace() ? null : await TagRepository.FindByNameAsync(id, tagName);
var userDictionary = new Dictionary<Guid, BlogUserDto>();
var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts));
@ -84,7 +84,7 @@ namespace Volo.Blogging.Posts
public async Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId)
{
var postCacheItems = await _postsCache.GetOrAddAsync(
var postCacheItems = await PostsCache.GetOrAddAsync(
blogId.ToString(),
async () => await GetTimeOrderedPostsAsync(blogId),
() => new DistributedCacheEntryOptions
@ -112,7 +112,7 @@ namespace Volo.Blogging.Posts
public async Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input)
{
var post = await _postRepository.GetPostByUrl(input.BlogId, input.Url);
var post = await PostRepository.GetPostByUrl(input.BlogId, input.Url);
post.IncreaseReadCount();
@ -132,7 +132,7 @@ namespace Volo.Blogging.Posts
public async Task<PostWithDetailsDto> GetAsync(Guid id)
{
var post = await _postRepository.GetAsync(id);
var post = await PostRepository.GetAsync(id);
var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post);
@ -151,22 +151,22 @@ namespace Volo.Blogging.Posts
[Authorize(BloggingPermissions.Posts.Delete)]
public async Task DeleteAsync(Guid id)
{
var post = await _postRepository.GetAsync(id);
var post = await PostRepository.GetAsync(id);
await AuthorizationService.CheckAsync(post, CommonOperations.Delete);
var tags = await GetTagsOfPostAsync(id);
await _tagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList());
await _commentRepository.DeleteOfPost(id);
await TagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList());
await CommentRepository.DeleteOfPost(id);
await _postRepository.DeleteAsync(id);
await PostRepository.DeleteAsync(id);
await PublishPostChangedEventAsync(post.BlogId);
}
[Authorize(BloggingPermissions.Posts.Update)]
public async Task<PostWithDetailsDto> UpdateAsync(Guid id, UpdatePostDto input)
{
var post = await _postRepository.GetAsync(id);
var post = await PostRepository.GetAsync(id);
input.Url = await RenameUrlIfItAlreadyExistAsync(input.BlogId, input.Url, post);
@ -179,7 +179,7 @@ namespace Volo.Blogging.Posts
post.Description = input.Description;
post.CoverImage = input.CoverImage;
post = await _postRepository.UpdateAsync(post);
post = await PostRepository.UpdateAsync(post);
var tagList = SplitTags(input.Tags);
await SaveTags(tagList, post);
@ -205,7 +205,7 @@ namespace Volo.Blogging.Posts
Description = input.Description
};
await _postRepository.InsertAsync(post);
await PostRepository.InsertAsync(post);
var tagList = SplitTags(input.Tags);
await SaveTags(tagList, post);
@ -216,14 +216,14 @@ namespace Volo.Blogging.Posts
private async Task<List<PostCacheItem>> GetTimeOrderedPostsAsync(Guid blogId)
{
var posts = await _postRepository.GetOrderedList(blogId);
var posts = await PostRepository.GetOrderedList(blogId);
return ObjectMapper.Map<List<Post>, List<PostCacheItem>>(posts);
}
private async Task<string> RenameUrlIfItAlreadyExistAsync(Guid blogId, string url, Post existingPost = null)
{
if (await _postRepository.IsPostUrlInUseAsync(blogId, url, existingPost?.Id))
if (await PostRepository.IsPostUrlInUseAsync(blogId, url, existingPost?.Id))
{
return url + "-" + Guid.NewGuid().ToString().Substring(0, 5);
}
@ -242,7 +242,7 @@ namespace Volo.Blogging.Posts
{
foreach (var oldTag in post.Tags.ToList())
{
var tag = await _tagRepository.GetAsync(oldTag.TagId);
var tag = await TagRepository.GetAsync(oldTag.TagId);
var oldTagNameInNewTags = newTags.FirstOrDefault(t => t == tag.Name);
@ -251,7 +251,7 @@ namespace Volo.Blogging.Posts
post.RemoveTag(oldTag.TagId);
tag.DecreaseUsageCount();
await _tagRepository.UpdateAsync(tag);
await TagRepository.UpdateAsync(tag);
}
else
{
@ -262,7 +262,7 @@ namespace Volo.Blogging.Posts
private async Task AddNewTags(IEnumerable<string> newTags, Post post)
{
var tags = await _tagRepository.GetListAsync(post.BlogId);
var tags = await TagRepository.GetListAsync(post.BlogId);
foreach (var newTag in newTags)
{
@ -270,12 +270,12 @@ namespace Volo.Blogging.Posts
if (tag == null)
{
tag = await _tagRepository.InsertAsync(new Tag(GuidGenerator.Create(), post.BlogId, newTag, 1));
tag = await TagRepository.InsertAsync(new Tag(GuidGenerator.Create(), post.BlogId, newTag, 1));
}
else
{
tag.IncreaseUsageCount();
tag = await _tagRepository.UpdateAsync(tag);
tag = await TagRepository.UpdateAsync(tag);
}
post.AddTag(tag.Id);
@ -284,9 +284,9 @@ namespace Volo.Blogging.Posts
private async Task<List<TagDto>> GetTagsOfPostAsync(Guid id)
{
var tagIds = (await _postRepository.GetAsync(id)).Tags;
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));
return ObjectMapper.Map<List<Tag>, List<TagDto>>(tags);
}
@ -309,7 +309,7 @@ namespace Volo.Blogging.Posts
private async Task PublishPostChangedEventAsync(Guid blogId)
{
await _localEventBus.PublishAsync(
await LocalEventBus.PublishAsync(
new PostChangedEvent
{
BlogId = blogId

8
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs

@ -8,11 +8,11 @@ namespace Volo.Blogging.Posts
{
public class PostAuthorizationHandler : AuthorizationHandler<OperationAuthorizationRequirement, Post>
{
private readonly IPermissionChecker _permissionChecker;
protected IPermissionChecker PermissionChecker { get; }
public PostAuthorizationHandler(IPermissionChecker permissionChecker)
{
_permissionChecker = permissionChecker;
PermissionChecker = permissionChecker;
}
protected async override Task HandleRequirementAsync(
@ -40,7 +40,7 @@ namespace Volo.Blogging.Posts
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete))
if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete))
{
return true;
}
@ -55,7 +55,7 @@ namespace Volo.Blogging.Posts
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Update))
if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Update))
{
return true;
}

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

@ -8,16 +8,16 @@ namespace Volo.Blogging.Tagging
{
public class TagAppService : BloggingAppServiceBase, ITagAppService
{
private readonly ITagRepository _tagRepository;
protected ITagRepository TagRepository { get; }
public TagAppService(ITagRepository tagRepository)
{
_tagRepository = tagRepository;
TagRepository = tagRepository;
}
public async Task<List<TagDto>> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input)
{
var postTags = (await _tagRepository.GetListAsync(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();

Loading…
Cancel
Save