public async Task <IEnumerable <CommentViewModel> > GetCommentsAsync(CommentSearchParams searchParams) { User user = await _userManager.FindByIdAsync(searchParams.UserId); Guard.Against.NullItem(user.Id, nameof(user)); var specification = new CommentFilterSpecification(searchParams); return(await _commentRepository.ListAsync <CommentViewModel>(specification, CommentHelpers.GetCommentMapperConfiguration())); }
public async Task <int> GetCommentsCountAsync(CommentSearchParams searchParams) { User user = await _userManager.FindByIdAsync(searchParams.UserId); Guard.Against.NullItem(user, nameof(user)); Post post = await _postRepository.GetByConditionAsync(x => x.Id == searchParams.PostId); Guard.Against.NullItem(post, nameof(post)); var specification = new CommentFilterSpecification(searchParams); return(await _commentRepository.GetTotalCountAsync(specification)); }
public async Task <IActionResult> GetMany([FromQuery] CommentSearchParams searchParams) { if (!BaseHelpers.IsPaginatonSearchParamsValid(searchParams, out ErrorResponse errorResponse)) { return(new BadRequestObjectResult(errorResponse)); } FilteredDataViewModel <CommentViewModel> result = await _mediator.Send(new GetCommentsQuery(searchParams)); return(Ok(new FilteredResponse <CommentViewModel>(searchParams) { Data = result.Data, Count = result.Count, })); }
public CommentFilterSpecification(CommentSearchParams searchParams) : base(x => (string.IsNullOrEmpty(searchParams.UserId) || (x.AuthorId == searchParams.UserId)) && (string.IsNullOrEmpty(searchParams.PostId) || (x.PostId == searchParams.PostId)) ) { AddIncludes(query => query.Include(x => x.Author).Include(x => x.CommentVotes) ); if (searchParams.OrderByDir.ToUpper() == "DESC") { ApplyFieldOrderByDescending(searchParams.SortBy); } else { ApplyFieldOrderBy(searchParams.SortBy); } ApplyPaging(searchParams.Offset, searchParams.Limit); }
public GetCommentsQuery(CommentSearchParams searchParams) { SearchParams = searchParams; }