Esempio n. 1
0
        /// <summary>
        /// 查询文章分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult <PageList <ArticlePageListResponse> > > QueryArticlePageAsync(ArticlePageRequest request)
        {
            var response = new ApiResult <PageList <ArticlePageListResponse> >();

            try
            {
                #region 拼接查询条件

                Expression <Func <Article, bool> > articleWhere = item => item.UserId == request.UserId && item.Status == 1;
                if (!string.IsNullOrEmpty(request.Title))
                {
                    articleWhere = articleWhere.And(item => item.Title == request.Title);
                }
                if (request.StartTime.HasValue && request.EndTime.HasValue)
                {
                    articleWhere = articleWhere.And(item => item.CreateTime >= request.StartTime.Value && item.CreateTime <= request.EndTime.Value);
                }

                #endregion

                var articles = await _articleRepository.TableNotTracking
                               .Where(articleWhere)
                               .OrderByDescending(item => item.IsTop)
                               .ThenByDescending(item => item.CreateTime)
                               .Select(item => new ArticlePageListResponse
                {
                    Id         = item.Id.ToString(),
                    Title      = item.Title,
                    Describe   = item.Describe,
                    CategoryId = item.CategoryId,
                    View       = item.View,
                    Comment    = item.Comment,
                    Like       = item.Like,
                    IsTop      = item.IsTop,
                    CreateTime = item.CreateTime
                })
                               .ToPageListAsync(request.PageParm.Page, request.PageParm.Size);

                foreach (var article in articles.Data)
                {
                    article.Like = await _articleCacheService.QueryLikeAsync(Convert.ToInt64(article.Id));

                    article.View = await _articleCacheService.QueryViewAsync(Convert.ToInt64(article.Id));
                }

                response.Code    = Code.Ok;
                response.Message = "查询成功";
                response.Data    = articles;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError($"查询文章分页异常;method={nameof(QueryArticlePageAsync)};param={request.ToJson()};exception messges={ex.Message}");
                response.Code    = Code.Error;
                response.Message = $"查询文章分页异常:{ex.Message}";
                return(response);
            }
        }
Esempio n. 2
0
 public async Task <ApiResult <PageList <ArticlePageListResponse> > > QueryArticlePageAsync([FromBody] ArticlePageRequest request)
 {
     return(await _articleService.QueryArticlePageAsync(request));
 }