Browse Source

Merge pull request #9965 from abpframework/liangshiwei/modules

Add async suffix to the application service asynchronous method
pull/9971/head
maliming 5 years ago
committed by GitHub
parent
commit
c7cda7b770
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs
  3. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Tagging/ITagAppService.cs
  4. 36
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  5. 2
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs
  6. 4
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs
  7. 4
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs
  8. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml.cs
  9. 2
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs
  10. 2
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs
  11. 8
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs
  12. 2
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  13. 4
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs

4
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) 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); var resetToken = await UserManager.GeneratePasswordResetTokenAsync(user);
await AccountEmailer.SendPasswordResetLinkAsync(user, resetToken, input.AppName, input.ReturnUrl, input.ReturnUrlHash); await AccountEmailer.SendPasswordResetLinkAsync(user, resetToken, input.AppName, input.ReturnUrl, input.ReturnUrlHash);
} }
@ -74,7 +74,7 @@ namespace Volo.Abp.Account
}); });
} }
protected virtual async Task<IdentityUser> GetUserByEmail(string email) protected virtual async Task<IdentityUser> GetUserByEmailAsync(string email)
{ {
var user = await UserManager.FindByEmailAsync(email); var user = await UserManager.FindByEmailAsync(email);
if (user == null) if (user == null)

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs

@ -7,7 +7,7 @@ namespace Volo.Blogging.Posts
{ {
public interface IPostAppService : IApplicationService public interface IPostAppService : IApplicationService
{ {
Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagName(Guid blogId, string tagName); Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagNameAsync(Guid blogId, string tagName);
Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId); Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId);

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 public interface ITagAppService : IApplicationService
{ {
Task<List<TagDto>> GetPopularTags(Guid blogId, GetPopularTagsInput input); Task<List<TagDto>> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input);
} }
} }

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

@ -41,24 +41,24 @@ namespace Volo.Blogging.Posts
_postsCache = postsCache; _postsCache = postsCache;
_localEventBus = localEventBus; _localEventBus = localEventBus;
} }
public async Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagName(Guid id, string tagName) public async Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagNameAsync(Guid id, string tagName)
{ {
var posts = await _postRepository.GetPostsByBlogId(id); var posts = await _postRepository.GetPostsByBlogId(id);
var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName); var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName);
var userDictionary = new Dictionary<Guid, BlogUserDto>(); var userDictionary = new Dictionary<Guid, BlogUserDto>();
var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts)); var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts));
foreach (var postDto in postDtos) foreach (var postDto in postDtos)
{ {
postDto.Tags = await GetTagsOfPost(postDto.Id); postDto.Tags = await GetTagsOfPostAsync(postDto.Id);
} }
if (tag != null) if (tag != null)
{ {
postDtos = await FilterPostsByTag(postDtos, tag); postDtos = await FilterPostsByTagAsync(postDtos, tag);
} }
foreach (var postDto in postDtos) foreach (var postDto in postDtos)
{ {
if (postDto.CreatorId.HasValue) if (postDto.CreatorId.HasValue)
@ -71,17 +71,17 @@ namespace Volo.Blogging.Posts
userDictionary[creatorUser.Id] = ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser); userDictionary[creatorUser.Id] = ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser);
} }
} }
if (userDictionary.ContainsKey(postDto.CreatorId.Value)) if (userDictionary.ContainsKey(postDto.CreatorId.Value))
{ {
postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
} }
} }
} }
return new ListResultDto<PostWithDetailsDto>(postDtos); return new ListResultDto<PostWithDetailsDto>(postDtos);
} }
public async Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId) public async Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId)
{ {
var postCacheItems = await _postsCache.GetOrAddAsync( var postCacheItems = await _postsCache.GetOrAddAsync(
@ -94,7 +94,7 @@ namespace Volo.Blogging.Posts
); );
var postsWithDetails = ObjectMapper.Map<List<PostCacheItem>, List<PostWithDetailsDto>>(postCacheItems); var postsWithDetails = ObjectMapper.Map<List<PostCacheItem>, List<PostWithDetailsDto>>(postCacheItems);
foreach (var post in postsWithDetails) foreach (var post in postsWithDetails)
{ {
if (post.CreatorId.HasValue) if (post.CreatorId.HasValue)
@ -106,7 +106,7 @@ namespace Volo.Blogging.Posts
} }
} }
} }
return new ListResultDto<PostWithDetailsDto>(postsWithDetails); return new ListResultDto<PostWithDetailsDto>(postsWithDetails);
} }
@ -118,7 +118,7 @@ namespace Volo.Blogging.Posts
var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post); var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post);
postDto.Tags = await GetTagsOfPost(postDto.Id); postDto.Tags = await GetTagsOfPostAsync(postDto.Id);
if (postDto.CreatorId.HasValue) if (postDto.CreatorId.HasValue)
{ {
@ -136,7 +136,7 @@ namespace Volo.Blogging.Posts
var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post); var postDto = ObjectMapper.Map<Post, PostWithDetailsDto>(post);
postDto.Tags = await GetTagsOfPost(postDto.Id); postDto.Tags = await GetTagsOfPostAsync(postDto.Id);
if (postDto.CreatorId.HasValue) if (postDto.CreatorId.HasValue)
{ {
@ -155,7 +155,7 @@ namespace Volo.Blogging.Posts
await AuthorizationService.CheckAsync(post, CommonOperations.Delete); 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 _tagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList());
await _commentRepository.DeleteOfPost(id); await _commentRepository.DeleteOfPost(id);
@ -220,7 +220,7 @@ namespace Volo.Blogging.Posts
return ObjectMapper.Map<List<Post>, List<PostCacheItem>>(posts); return ObjectMapper.Map<List<Post>, List<PostCacheItem>>(posts);
} }
private async Task<string> RenameUrlIfItAlreadyExistAsync(Guid blogId, string url, Post existingPost = null) 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))
@ -282,7 +282,7 @@ namespace Volo.Blogging.Posts
} }
} }
private async Task<List<TagDto>> GetTagsOfPost(Guid id) private async Task<List<TagDto>> GetTagsOfPostAsync(Guid id)
{ {
var tagIds = (await _postRepository.GetAsync(id)).Tags; var tagIds = (await _postRepository.GetAsync(id)).Tags;
@ -300,7 +300,7 @@ namespace Volo.Blogging.Posts
return new List<string>(tags.Split(",").Select(t => t.Trim())); return new List<string>(tags.Split(",").Select(t => t.Trim()));
} }
private Task<List<PostWithDetailsDto>> FilterPostsByTag(IEnumerable<PostWithDetailsDto> allPostDtos, Tag tag) private Task<List<PostWithDetailsDto>> FilterPostsByTagAsync(IEnumerable<PostWithDetailsDto> allPostDtos, Tag tag)
{ {
var filteredPostDtos = allPostDtos.Where(p => p.Tags?.Any(t => t.Id == tag.Id) ?? false).ToList(); var filteredPostDtos = allPostDtos.Where(p => p.Tags?.Any(t => t.Id == tag.Id) ?? false).ToList();

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

@ -15,7 +15,7 @@ namespace Volo.Blogging.Tagging
_tagRepository = tagRepository; _tagRepository = tagRepository;
} }
public async Task<List<TagDto>> GetPopularTags(Guid blogId, GetPopularTagsInput input) 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) .WhereIf(input.MinimumPostCount != null, t=>t.UsageCount >= input.MinimumPostCount)

4
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs

@ -22,9 +22,9 @@ namespace Volo.Blogging
[HttpGet] [HttpGet]
[Route("{blogId}/all")] [Route("{blogId}/all")]
public Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagName(Guid blogId, string tagName) public Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagNameAsync(Guid blogId, string tagName)
{ {
return _postAppService.GetListByBlogIdAndTagName(blogId, tagName); return _postAppService.GetListByBlogIdAndTagNameAsync(blogId, tagName);
} }
[HttpGet] [HttpGet]

4
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs

@ -23,9 +23,9 @@ namespace Volo.Blogging
[HttpGet] [HttpGet]
[Route("popular/{blogId}")] [Route("popular/{blogId}")]
public Task<List<TagDto>> GetPopularTags(Guid blogId, GetPopularTagsInput input) public Task<List<TagDto>> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input)
{ {
return _tagAppService.GetPopularTags(blogId, input); return _tagAppService.GetPopularTagsAsync(blogId, input);
} }
} }
} }

4
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); Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Posts = (await _postAppService.GetListByBlogIdAndTagName(Blog.Id, TagName)).Items; Posts = (await _postAppService.GetListByBlogIdAndTagNameAsync(Blog.Id, TagName)).Items;
PopularTags = (await _tagAppService.GetPopularTags(Blog.Id, new GetPopularTagsInput {ResultCount = 10, MinimumPostCount = 2})); PopularTags = (await _tagAppService.GetPopularTagsAsync(Blog.Id, new GetPopularTagsInput {ResultCount = 10, MinimumPostCount = 2}));
return Page(); return Page();
} }

2
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() public async Task Should_Get_List_Of_Posts()
{ {
var blogId = (await _blogRepository.GetListAsync()).First().Id; 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); posts.Items.Count.ShouldBeGreaterThan(0);
} }

2
modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/TagAppService_Tests.cs

@ -23,7 +23,7 @@ namespace Volo.Blogging
[Fact] [Fact]
public async Task Should_Get_Popular_Tags() 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); tags.Count.ShouldBeGreaterThan(0);
} }

8
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs

@ -8,13 +8,13 @@ namespace Volo.Docs.Projects
public interface IProjectAppService : IApplicationService public interface IProjectAppService : IApplicationService
{ {
Task<ListResultDto<ProjectDto>> GetListAsync(); Task<ListResultDto<ProjectDto>> GetListAsync();
Task<ProjectDto> GetAsync(string shortName); Task<ProjectDto> GetAsync(string shortName);
Task<ListResultDto<VersionInfoDto>> GetVersionsAsync(string shortName); Task<ListResultDto<VersionInfoDto>> GetVersionsAsync(string shortName);
Task<string> GetDefaultLanguageCode(string shortName, string version); Task<string> GetDefaultLanguageCodeAsync(string shortName, string version);
Task<LanguageConfig> GetLanguageListAsync(string shortName, string version); Task<LanguageConfig> GetLanguageListAsync(string shortName, string version);
} }
} }

2
modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs

@ -94,7 +94,7 @@ namespace Volo.Docs.Projects
return await GetLanguageListInternalAsync(shortName, version); return await GetLanguageListInternalAsync(shortName, version);
} }
public async Task<string> GetDefaultLanguageCode(string shortName, string version) public async Task<string> GetDefaultLanguageCodeAsync(string shortName, string version)
{ {
var languageList = await GetLanguageListInternalAsync(shortName, version); var languageList = await GetLanguageListInternalAsync(shortName, version);

4
modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs

@ -36,9 +36,9 @@ namespace Volo.Docs.Projects
[HttpGet] [HttpGet]
[Route("{shortName}/defaultLanguage")] [Route("{shortName}/defaultLanguage")]
public Task<string> GetDefaultLanguageCode(string shortName,string version) public Task<string> GetDefaultLanguageCodeAsync(string shortName,string version)
{ {
return ProjectAppService.GetDefaultLanguageCode(shortName, version); return ProjectAppService.GetDefaultLanguageCodeAsync(shortName, version);
} }
[HttpGet] [HttpGet]

Loading…
Cancel
Save