public async Task <List <Post> > Filter(PostFilterInDto filterOptions) { var filtered = _context.Posts .Include(p => p.User) .Include(p => p.PostTagAssociations) .TimeRangeFilter(filterOptions) .Where(post => ((string.IsNullOrWhiteSpace(filterOptions.TitleMatch) || post.Title.Contains(filterOptions.TitleMatch)) && (filterOptions.CategoryId == null || filterOptions.CategoryId == post.CategoryId) && (filterOptions.StatusId == null || filterOptions.StatusId == post.StatusId) && (filterOptions.TagIds == null || post.PostTagAssociations.Any(a => filterOptions.TagIds.Contains(a.TagId))) && (filterOptions.UserId == null || filterOptions.UserId == post.UserId))); var ordered = filterOptions.CreateTimeDesc ? filtered.OrderByDescending(p => p.CreateTime) : filtered.OrderBy(p => p.CreateTime); return(await ordered.SkipTakePaging(filterOptions).ToListAsync()); }
public async Task <ActionResult <ResultOutDto <List <Post> > > > GetPosts([FromQuery] PostFilterInDto filterOptions) { return(Ok(ResultOutDtoBuilder.Success(await _postService.Filter(filterOptions)))); }