Feat/pagination
Implemented a pagination system flexible enough to be used by any model desired.
The requests are encapsulated as an object in RequestPage
specifying which page desired and the amount of results per page.
Returned is a Page
object holding the result and is to be queried for the next PageRequest
to request the next page.
This class calculates the last page available and does not allow getting the PageRequest
for the next page. Same applies for trying to get the previous page when we are on the first page.
In both situations the current page is returned, which essentially means we are fetching the same page over again. This can be addressed by dissallowing the user from pressing the corresponding previous and next buttons in the UI.
The repositories extending PagingAndSortingRepository
takes a PageRequest
and fetches the entities only for that given page.
That means if we request page number two with a page size of 10, then 0+10=10 is the first entity fetched and 10+10=20 the last entity fetched. These 10 results between 10 and 20 are contained in a Page
object.
By storing the requests as a PageRequest
object we encapsulate a paginated request which in practice means that we can let the user decide how many entities he or she wants to view per page.
A Sort
object can also be stored in the RequestPage
object for ordering the results. @stianfmo is working on this as of this moment.
Please refer to AlbumServiceTest.java
to see how this works in practice.