Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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 }
     }));
 }
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 public Task <List <TagDto> > GetPopularTags(Guid blogId, GetPopularTagsInput input)
 {
     return(_tagAppService.GetPopularTags(blogId, input));
 }