Class PagingRequest

java.lang.Object
codes.thischwa.cf.model.PagingRequest

public class PagingRequest extends Object
Represents a request model for paginated data.

This class encapsulates the page number and the number of items per page for a paginated request, along with utility methods for constructing and retrieving pagination parameters.

Key functionalities:

  • Creating a PagingRequest instance with specific pagination values using the of method.
  • Creating a default PagingRequest with predefined pagination values.
  • Retrieving pagination parameters as a key-value map.
  • Generating a query string representation for the pagination parameters.
  • Method Details

    • of

      public static PagingRequest of(int page, int perPage)
      Creates a new PagingRequest instance with the specified page number and items per page.
      Parameters:
      page - the page number to be requested
      perPage - the number of items to be included per page
      Returns:
      a new PagingRequest instance with the provided parameters
    • defaultPaging

      public static PagingRequest defaultPaging()
      Creates a default PagingRequest instance with a page number set to 1 and a high number of items per page (5,000,000) to accommodate large dataset requests.
      Returns:
      a default PagingRequest instance with predefined pagination parameters
    • getPagingParams

      public Map<String,String> getPagingParams()
      Retrieves the pagination parameters in a key-value map format.
      Returns:
      a map containing the pagination parameters, where the key "page" indicates the current page number and the key "perPage" indicates the number of items per page.
    • addQueryString

      public String addQueryString(String endpoint)
      Appends a query string with pagination parameters (page and perPage) to the provided endpoint.
      Parameters:
      endpoint - the base URL or API endpoint to which the query string will be appended
      Returns:
      the complete URL with the appended query string for pagination