From f4dd7005600dbbb2dc19edb5f9b281b87edac07b Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 3 Sep 2021 13:22:29 +0800 Subject: [PATCH 1/2] Add async suffix to the application service asynchronous method --- .../Volo/Blogging/Posts/IPostAppService.cs | 2 +- .../Volo/Blogging/Tagging/ITagAppService.cs | 2 +- .../Volo/Blogging/Posts/PostAppService.cs | 2 +- .../Volo/Blogging/Tagging/TagAppService.cs | 2 +- .../Volo/Blogging/PostsController.cs | 4 ++-- .../Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs | 4 ++-- .../Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs | 4 ++-- .../Volo/Blogging/PostAppService_Tests.cs | 2 +- .../Volo/Blogging/TagAppService_Tests.cs | 2 +- .../Volo/Docs/Projects/IProjectAppService.cs | 8 ++++---- .../Volo/Docs/Projects/ProjectAppService.cs | 2 +- .../Volo/Docs/Projects/DocsProjectController.cs | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs index 55b64d29de..8f1f2c251d 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs @@ -7,7 +7,7 @@ namespace Volo.Blogging.Posts { public interface IPostAppService : IApplicationService { - Task> GetListByBlogIdAndTagName(Guid blogId, string tagName); + Task> GetListByBlogIdAndTagNameAsync(Guid blogId, string tagName); Task> GetTimeOrderedListAsync(Guid blogId); 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 8ee283dbcd..b2013bc2fd 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(Guid blogId, GetPopularTagsInput input); + Task> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input); } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index be53ac4139..65b8575091 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -42,7 +42,7 @@ namespace Volo.Blogging.Posts _localEventBus = localEventBus; } - public async Task> GetListByBlogIdAndTagName(Guid id, string tagName) + public async Task> GetListByBlogIdAndTagNameAsync(Guid id, string tagName) { var posts = await _postRepository.GetPostsByBlogId(id); var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName); 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 7ea56ea2c8..440d245946 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 @@ -15,7 +15,7 @@ namespace Volo.Blogging.Tagging _tagRepository = tagRepository; } - public async Task> GetPopularTags(Guid blogId, GetPopularTagsInput input) + public async Task> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input) { var postTags = (await _tagRepository.GetListAsync(blogId)).OrderByDescending(t=>t.UsageCount) .WhereIf(input.MinimumPostCount != null, t=>t.UsageCount >= input.MinimumPostCount) diff --git a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs index f7a1c01703..f3d67af815 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs @@ -22,9 +22,9 @@ namespace Volo.Blogging [HttpGet] [Route("{blogId}/all")] - public Task> GetListByBlogIdAndTagName(Guid blogId, string tagName) + public Task> GetListByBlogIdAndTagNameAsync(Guid blogId, string tagName) { - return _postAppService.GetListByBlogIdAndTagName(blogId, tagName); + return _postAppService.GetListByBlogIdAndTagNameAsync(blogId, tagName); } [HttpGet] diff --git a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs index 6f17623a5e..4c2c34db44 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs @@ -23,9 +23,9 @@ namespace Volo.Blogging [HttpGet] [Route("popular/{blogId}")] - public Task> GetPopularTags(Guid blogId, GetPopularTagsInput input) + public Task> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input) { - return _tagAppService.GetPopularTags(blogId, input); + return _tagAppService.GetPopularTagsAsync(blogId, input); } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs index 77a54ffa11..2340d16917 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs @@ -44,8 +44,8 @@ namespace Volo.Blogging.Pages.Blog.Posts } Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - Posts = (await _postAppService.GetListByBlogIdAndTagName(Blog.Id, TagName)).Items; - PopularTags = (await _tagAppService.GetPopularTags(Blog.Id, new GetPopularTagsInput {ResultCount = 10, MinimumPostCount = 2})); + Posts = (await _postAppService.GetListByBlogIdAndTagNameAsync(Blog.Id, TagName)).Items; + PopularTags = (await _tagAppService.GetPopularTagsAsync(Blog.Id, new GetPopularTagsInput {ResultCount = 10, MinimumPostCount = 2})); return Page(); } diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs index 654ddcbe44..8e3c8a253a 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs @@ -25,7 +25,7 @@ namespace Volo.Blogging public async Task Should_Get_List_Of_Posts() { var blogId = (await _blogRepository.GetListAsync()).First().Id; - var posts = await _postAppService.GetListByBlogIdAndTagName(blogId, null); + var posts = await _postAppService.GetListByBlogIdAndTagNameAsync(blogId, null); posts.Items.Count.ShouldBeGreaterThan(0); } 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 d152eead55..7773e88820 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(_bloggingTestData.Blog1Id, new GetPopularTagsInput() {ResultCount = 5, MinimumPostCount = 0 }); + var tags = await _tagAppService.GetPopularTagsAsync(_bloggingTestData.Blog1Id, new GetPopularTagsInput() {ResultCount = 5, MinimumPostCount = 0 }); tags.Count.ShouldBeGreaterThan(0); } diff --git a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs index 44f4cbf3b8..b93fb09e77 100644 --- a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs +++ b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs @@ -8,13 +8,13 @@ namespace Volo.Docs.Projects public interface IProjectAppService : IApplicationService { Task> GetListAsync(); - + Task GetAsync(string shortName); - + Task> GetVersionsAsync(string shortName); - Task GetDefaultLanguageCode(string shortName, string version); + Task GetDefaultLanguageCodeAsync(string shortName, string version); Task GetLanguageListAsync(string shortName, string version); } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs index 1f5a8d4c91..f07dc8a361 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs @@ -94,7 +94,7 @@ namespace Volo.Docs.Projects return await GetLanguageListInternalAsync(shortName, version); } - public async Task GetDefaultLanguageCode(string shortName, string version) + public async Task GetDefaultLanguageCodeAsync(string shortName, string version) { var languageList = await GetLanguageListInternalAsync(shortName, version); diff --git a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs index 039f13a44e..e02c320757 100644 --- a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs +++ b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs @@ -36,9 +36,9 @@ namespace Volo.Docs.Projects [HttpGet] [Route("{shortName}/defaultLanguage")] - public Task GetDefaultLanguageCode(string shortName,string version) + public Task GetDefaultLanguageCodeAsync(string shortName,string version) { - return ProjectAppService.GetDefaultLanguageCode(shortName, version); + return ProjectAppService.GetDefaultLanguageCodeAsync(shortName, version); } [HttpGet] From c3919b412585d1515d097b362d73bd66e6653582 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 3 Sep 2021 13:42:24 +0800 Subject: [PATCH 2/2] Add async suffix to the application service asynchronous method --- .../Volo/Abp/Account/AccountAppService.cs | 4 +-- .../Volo/Blogging/Posts/PostAppService.cs | 34 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs index 05ff98b35b..5c6612d1cc 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs @@ -55,7 +55,7 @@ namespace Volo.Abp.Account public virtual async Task SendPasswordResetCodeAsync(SendPasswordResetCodeDto input) { - var user = await GetUserByEmail(input.Email); + var user = await GetUserByEmailAsync(input.Email); var resetToken = await UserManager.GeneratePasswordResetTokenAsync(user); await AccountEmailer.SendPasswordResetLinkAsync(user, resetToken, input.AppName, input.ReturnUrl, input.ReturnUrlHash); } @@ -74,7 +74,7 @@ namespace Volo.Abp.Account }); } - protected virtual async Task GetUserByEmail(string email) + protected virtual async Task GetUserByEmailAsync(string email) { var user = await UserManager.FindByEmailAsync(email); if (user == null) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 65b8575091..a886649104 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -41,24 +41,24 @@ namespace Volo.Blogging.Posts _postsCache = postsCache; _localEventBus = localEventBus; } - + public async Task> GetListByBlogIdAndTagNameAsync(Guid id, string tagName) { var posts = await _postRepository.GetPostsByBlogId(id); var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName); var userDictionary = new Dictionary(); var postDtos = new List(ObjectMapper.Map, List>(posts)); - + foreach (var postDto in postDtos) { - postDto.Tags = await GetTagsOfPost(postDto.Id); + postDto.Tags = await GetTagsOfPostAsync(postDto.Id); } - + if (tag != null) { - postDtos = await FilterPostsByTag(postDtos, tag); + postDtos = await FilterPostsByTagAsync(postDtos, tag); } - + foreach (var postDto in postDtos) { if (postDto.CreatorId.HasValue) @@ -71,17 +71,17 @@ namespace Volo.Blogging.Posts userDictionary[creatorUser.Id] = ObjectMapper.Map(creatorUser); } } - + if (userDictionary.ContainsKey(postDto.CreatorId.Value)) { postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; } } } - + return new ListResultDto(postDtos); } - + public async Task> GetTimeOrderedListAsync(Guid blogId) { var postCacheItems = await _postsCache.GetOrAddAsync( @@ -94,7 +94,7 @@ namespace Volo.Blogging.Posts ); var postsWithDetails = ObjectMapper.Map, List>(postCacheItems); - + foreach (var post in postsWithDetails) { if (post.CreatorId.HasValue) @@ -106,7 +106,7 @@ namespace Volo.Blogging.Posts } } } - + return new ListResultDto(postsWithDetails); } @@ -118,7 +118,7 @@ namespace Volo.Blogging.Posts var postDto = ObjectMapper.Map(post); - postDto.Tags = await GetTagsOfPost(postDto.Id); + postDto.Tags = await GetTagsOfPostAsync(postDto.Id); if (postDto.CreatorId.HasValue) { @@ -136,7 +136,7 @@ namespace Volo.Blogging.Posts var postDto = ObjectMapper.Map(post); - postDto.Tags = await GetTagsOfPost(postDto.Id); + postDto.Tags = await GetTagsOfPostAsync(postDto.Id); if (postDto.CreatorId.HasValue) { @@ -155,7 +155,7 @@ namespace Volo.Blogging.Posts await AuthorizationService.CheckAsync(post, CommonOperations.Delete); - var tags = await GetTagsOfPost(id); + var tags = await GetTagsOfPostAsync(id); await _tagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList()); await _commentRepository.DeleteOfPost(id); @@ -220,7 +220,7 @@ namespace Volo.Blogging.Posts return ObjectMapper.Map, List>(posts); } - + private async Task RenameUrlIfItAlreadyExistAsync(Guid blogId, string url, Post existingPost = null) { if (await _postRepository.IsPostUrlInUseAsync(blogId, url, existingPost?.Id)) @@ -282,7 +282,7 @@ namespace Volo.Blogging.Posts } } - private async Task> GetTagsOfPost(Guid id) + private async Task> GetTagsOfPostAsync(Guid id) { var tagIds = (await _postRepository.GetAsync(id)).Tags; @@ -300,7 +300,7 @@ namespace Volo.Blogging.Posts return new List(tags.Split(",").Select(t => t.Trim())); } - private Task> FilterPostsByTag(IEnumerable allPostDtos, Tag tag) + private Task> FilterPostsByTagAsync(IEnumerable allPostDtos, Tag tag) { var filteredPostDtos = allPostDtos.Where(p => p.Tags?.Any(t => t.Id == tag.Id) ?? false).ToList();