public async Task <IActionResult> GetReplies(string postId, int page) { const int pageSize = 20; // post exist var pid = XUtils.ParseId(postId); var post = await Context.Posts.FirstOrDefaultAsync(p => p.Id == pid); if (post == null) { return(new ApiError(MyErrorCode.IdNotFound, "Post id not found").Wrap()); } // get var query = (from p in Context.Replies.Where(p => p.PostId == pid) join q in Context.Users on p.SenderId equals q.Id select new { reply = p, user = q }) .OrderBy(p => p.reply.CreatedAt).ThenBy(p => p.reply.Id); var data = await query.Skip(pageSize *page).Take(pageSize).ToListAsync(); var repliesV = data.Select(p => QReply.NormalView(p.reply, p.user)); return(Ok(repliesV)); }
public async Task <IActionResult> SearchReplies(string word, int page) { word ??= ""; page = Math.Max(0, page); const int pageSize = 20; var query = from p in Context.Replies where p.TextTsv.Matches(EF.Functions.WebSearchToTsQuery("testzhcfg", word)) join q in Context.Users on p.SenderId equals q.Id orderby p.TextTsv.RankCoverDensity(EF.Functions.WebSearchToTsQuery("testzhcfg", word)) descending select new { reply = p, user = q }; var data = await query.Skip(pageSize *page).Take(pageSize).ToListAsync(); var repliesV = data.Select(p => QReply.NormalView(p.reply, p.user)); return(Ok(repliesV)); }