joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

Fixed links.last when there are no any items in response #232

Closed sergey-litvinov-work closed 4 years ago

sergey-litvinov-work commented 4 years ago

Hi Jouke,

Looks like we missed one more case initially. When endpoint doesn't return any items, then links.last will have incorrect result.

If we would use 1 as first page number, then the response would be

{
  "data" : [ ],
  "links" : {
    "self" : "https://some/v5/equipment/",
    "first" : "https://some/v5/equipment/?page[number]=1",
    "last" : "https://some/v5/equipment/?page[number]=0"
  }
}

and last has page[number]=0 that isn't correct and should be the same as first. And if we don't have custom firstPage and by default it's 0, then response would be

{
  "data" : [ ],
  "links" : {
    "self" : "https://some/v5/equipment/",
    "first" : "https://some/v5/equipment/?page[number]=1",
    "last" : "https://some/v5/equipment/?page[number]=-1"
  }
}

This PR is the fix for that logic and also a couple of unit tests to cover this scenario

sergey-litvinov-work commented 4 years ago

Thanks!