Пример #1
0
        public async Task <ActionResult <PaginationResult <CommentDto> > > GetComments(
            [FromQuery] long thread,
            [FromQuery] int?page,
            [FromQuery] long?highlight
            )
        {
            var total = await _commentsRepo.CountComments(thread);

            // If a highlight has been requested, get the page on which the highlighted comment would be.
            // If not, simply return the requested page or the first page if requested page is null.
            // `highlight - 1` offsets the fact, that the requested IDs start from 1, not 0
            var p = highlight.HasValue
                ? (int)Math.Ceiling((double)(total - (highlight - 1)) / _ogmaConfig.CommentsPerPage)
                : Math.Max(1, page ?? 1);

            // Send auth data
            Response.Headers.Add("X-Authenticated", (User?.Identity?.IsAuthenticated ?? false).ToString());

            return(new PaginationResult <CommentDto>
            {
                Elements = await _commentsRepo.GetPaginated(thread, p, _ogmaConfig.CommentsPerPage),
                Total = total,
                Page = p,
                Pages = (int)Math.Ceiling((double)total / _ogmaConfig.CommentsPerPage),
                PerPage = _ogmaConfig.CommentsPerPage
            });
        }