server_utils v0.2.2 ServerUtils.Parsers.Pagination.Classic.Parser

Module to get an integer() or a PageParams.t struct from a request map.

In case of page params parse, it validates the maximum page size request and provides the configured maximum param if it is exceeded.

This project provides a default value, but they can be overriding when using this module as well.

Link to this section Summary

Functions

Parses a page params from a request params map

Link to this section Functions

Link to this function parse_page_params(params_map, opts \\ [])

Parses a page params from a request params map.

It returns the PageParams.t with the given values.

If the given page size exceeds the maxim page size or equal or less than 0, then the default value is returned

Examples

iex> Elixir.ServerUtils.Parsers.Pagination.Classic.Parser.parse_page_params(%{"page_number" => 5, "page_size" => 23})
%ServerUtils.Pagination.Classic.PageRequest{page_number: 5, page_size: 23}

# With a configured max_page_size of 50
iex> Elixir.ServerUtils.Parsers.Pagination.Classic.Parser.parse_page_params(%{"page_number" => 5, "page_size" => 9000})
%ServerUtils.Pagination.Classic.PageRequest{page_number: 5,
  page_size: 25
}

iex> Elixir.ServerUtils.Parsers.Pagination.Classic.Parser.parse_page_params(%{"page_number" => 5, "page_size" => 0})
%ServerUtils.Pagination.Classic.PageRequest{page_number: 5, page_size: 10}