Skip to content

Commit 74c5010

Browse files
committed
fix(pageManager): handle case when current page = 0
1 parent a1d9f7d commit 74c5010

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/JsonApiDotNetCore/Internal/PageManager.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@ public class PageManager
1111
public int DefaultPageSize { get; set; }
1212
public int CurrentPage { get; set; }
1313
public bool IsPaginated => PageSize > 0;
14-
public int TotalPages => (TotalRecords == 0) ? -1: (int)Math.Ceiling(decimal.Divide(TotalRecords, PageSize));
14+
public int TotalPages => (TotalRecords == 0) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords, PageSize));
1515

1616
public RootLinks GetPageLinks(LinkBuilder linkBuilder)
17-
{
18-
if(!IsPaginated || (CurrentPage == 1 && TotalPages <= 0))
17+
{
18+
if (ShouldIncludeLinksObject())
1919
return null;
20-
20+
2121
var rootLinks = new RootLinks();
2222

23-
if(CurrentPage > 1)
23+
if (CurrentPage > 1)
2424
rootLinks.First = linkBuilder.GetPageLink(1, PageSize);
2525

26-
if(CurrentPage > 1)
26+
if (CurrentPage > 1)
2727
rootLinks.Prev = linkBuilder.GetPageLink(CurrentPage - 1, PageSize);
28-
29-
if(CurrentPage < TotalPages)
28+
29+
if (CurrentPage < TotalPages)
3030
rootLinks.Next = linkBuilder.GetPageLink(CurrentPage + 1, PageSize);
31-
32-
if(TotalPages > 0)
31+
32+
if (TotalPages > 0)
3333
rootLinks.Last = linkBuilder.GetPageLink(TotalPages, PageSize);
3434

3535
return rootLinks;
3636
}
37+
38+
private bool ShouldIncludeLinksObject() => (!IsPaginated || ((CurrentPage == 1 || CurrentPage == 0) && TotalPages <= 0));
3739
}
3840
}

0 commit comments

Comments
 (0)