示例#1
0
        public IActionResult GetCommentsByPost(int postId, int page = 0, int pageSize = standardPageSize)
        {
            var totalComments = _dataService.amountComments(postId);
            var totalPages    = GetTotalPages(pageSize, totalComments);

            if (page > totalPages - 1)
            {
                page = 0;
            }

            var comments = _dataService.getCommments(postId, page, pageSize);

            if (comments == null)
            {
                return(NotFound());
            }
            var result = new
            {
                Total = totalComments,
                Pages = totalPages,
                Page  = page,
                Prev  = Link(nameof(GetCommentsByPost), page, pageSize, -1, () => page > 0),
                Next  = Link(nameof(GetCommentsByPost), page, pageSize, 1, () => page < totalPages - 1),
                Url   = Link(nameof(GetCommentsByPost), page, pageSize),
                Data  = comments
            };

            return(Ok(result));
        }
示例#2
0
        public IActionResult GetCommentsByPost(int postId, int page = 0, int pageSize = standardPageSize)
        {
            var comments = _dataService.getCommments(postId, page, pageSize);

            if (comments == null)
            {
                return(NotFound());
            }
            return(Ok(comments));
        }