public async Task <PagedResC <TextPostRes> > GetPageDesc(PagedReqC req, long userId) { var user = UnitOfWork.AppUsers.GetById(userId); if (user == null) { throw new BusinnessException("Invalid user id: " + userId); } // Create filters only if this is a first page request List <Expression <Func <TextPost, bool> > > filters = null; var isFirstPageReq = string.IsNullOrWhiteSpace(req.ContinuationToken); // a non-empty token indicates a next page request if (isFirstPageReq) { filters = new List <Expression <Func <TextPost, bool> > >(); // Although incidentally userId is also partition key, this serves as a reference to implement filters with pagination // Note: Only paths included for indexing in the collection, can be added here as filters. filters.Add(p => p.CreatedByUserId == userId); // user can see only his posts // you may add more filters as desired here } // Get page var page = await UnitOfWork.TextPostRepo.GetPageDescendingAsync <long>(req.ContinuationToken, userId, filters); // Map to specific activities var resItems = Mapper.Map <IEnumerable <TextPostRes> >(page.Items); return(new PagedResC <TextPostRes>(resItems, page.ContinuationToken)); }
public async Task <IHttpActionResult> Page(PagedReqC req) { var userId = GetUserIdFromContext(); return(Ok(await _postsService.GetPageDesc(req, userId))); }