Surgex.Parser.SortParser (Surgex v5.0.0) View Source

Parses the JSON API's sort parameter according to the JSON API spec.

Produces a {direction, column} tuple, in which direction is either :asc or :desc and column is a safely atomized and underscored column name.

Link to this section Summary

Functions

Flattens the result of the parser (sort tuple) into *_by and *_direction keys.

Link to this section Functions

Specs

flatten({:ok, Keyword.t()}, atom()) :: {:ok, {:asc | :desc, atom()}}

Flattens the result of the parser (sort tuple) into *_by and *_direction keys.

Examples

iex> SortParser.flatten({:ok, sort: {:asc, :col}}, :sort)
{:ok, sort_by: :col, sort_direction: :asc}