public async Task <List <PopularTagDto> > GetPopularTags(GetPopularTagsInput input) { var postTags = await _postTagRepository.GetListAsync(); var postTagsGrouped = postTags.GroupBy(x => x.PostId) .OrderByDescending(g => g.Count()) .SelectMany(g => g).Select(t => t.TagId).Distinct().ToList(); var popularTagDtos = new List <PopularTagDto>(); for (var i = 0; i < input.ResultCount && i < postTagsGrouped.Count; i++) { var tagId = postTagsGrouped[i]; var count = postTags.Count(t => t.TagId == tagId); if (count < input.MinimumPostCount) { break; } var tag = await _tagRepository.GetAsync(tagId); popularTagDtos.Add(new PopularTagDto { Tag = ObjectMapper.Map <Tag, TagDto>(tag), Count = count }); } return(popularTagDtos); }
public virtual async Task <List <TagDto> > GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input) { return(await RequestAsync <List <TagDto> >(nameof(GetPopularTagsAsync), new ClientProxyRequestTypeValue { { typeof(Guid), blogId }, { typeof(GetPopularTagsInput), input } })); }
public async Task <List <TagDto> > GetPopularTags(Guid blogId, GetPopularTagsInput input) { var postTags = (await _tagRepository.GetListAsync(blogId)).OrderByDescending(t => t.UsageCount) .WhereIf(input.MinimumPostCount != null, t => t.UsageCount >= input.MinimumPostCount) .Take(input.ResultCount).ToList(); return(new List <TagDto>( ObjectMapper.Map <List <Tag>, List <TagDto> >(postTags))); }
/// <summary> /// 获取流行的标签 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <List <TagListDto> > GetPopularTags(GetPopularTagsInput input) { var blogTags = await _tagRepository.GetAllListAsync(); var postTags = blogTags.OrderByDescending(t => t.UsageCount) .WhereIf(input.MinimumPostCount != null, t => t.UsageCount >= input.MinimumPostCount) .Take(input.ResultCount).ToList(); var dtos = ObjectMapper.Map <List <TagListDto> >(postTags); return(dtos); }
public Task <List <TagDto> > GetPopularTags(Guid blogId, GetPopularTagsInput input) { return(_tagAppService.GetPopularTags(blogId, input)); }