Exemplo n.º 1
0
        public async Task <PageResultDto <FeedDto> > SearchAsync(FeedQuerySearch querySearch)
        {
            var query = _unitOfWork.FeedRepository.FindAll();

            if (!string.IsNullOrEmpty(querySearch.SearchKey))
            {
                query = query.Where(x => x.Content.Contains(querySearch.SearchKey));
            }

            if (!string.IsNullOrEmpty(querySearch.UserSlug))
            {
                query = query.Where(x => x.UserSlug.Equals(querySearch.UserSlug));
            }

            var feeds = await query.OrderByDescending(x => x.CreatedAt).Skip(querySearch.GetSkip()).Take(querySearch.GetTake()).ToListAsync();

            var result = new PageResultDto <FeedDto>(await query.CountAsync(), GetTotalPage(await query.CountAsync(), querySearch.GetTake()), feeds.Select(x => x.ToDto()).ToList());

            foreach (var item in result.Items)
            {
                var user = await _unitOfWork.UserRepository
                           .FindAll(x => x.Id.Equals(item.CreatedBy))
                           .Include(x => x.UserDetail)
                           .SingleOrDefaultAsync();

                item.FullName  = $"{user?.UserDetail?.FirstName} {user?.UserDetail?.LastName}";
                item.AvatarUrl = user?.UserDetail?.Avatar ?? $"{ApiUrl}/assets/no_image.png";
                item.UserSlug  = querySearch.UserSlug;
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get([FromQuery] FeedQuerySearch querySearch)
        {
            var feeds = await _feedService.SearchAsync(querySearch);

            foreach (var feed in feeds.Items)
            {
                var comments = await _commentService.SearchAsync(new CommentQuerySearch { ReferId = feed.Id, Size = 5 });

                comments.Items.Where(x => x.CreatedBy.Equals(feed.CreatedBy)).ToList().ForEach(x => x.ProfilePictureUrl = feed.AvatarUrl);

                feed.Comments = comments;
            }

            return(Ok(feeds));
        }
Exemplo n.º 3
0
 public async Task <HttpResponseMessage> SearchAsync(FeedQuerySearch querySearch)
 {
     return(await _oppJarProxy.GetAsync(string.Format(SEARCH, querySearch.GetQueryString())));
 }