JSONAPI.Controller

This module is a grab bag of functions that are useful when parsing query strings for JSONAPI.

Your goto should be clean_params2

> params = JSONAPI.Query.clean_params(params)
> %{ filter: %{}, sort: [], include: %{}}

You might also find get!(User, id) to be handy.

This whole module needs to be cleaned up and standardized.

Source

Summary

clean_params(params)

Will take a standards string key => val params map and parse out useful pieces for JSONAPI

get!(module, id)

Gets the module from the current Repo raises JSONAPI.ResourceNotFound otherwise. Can accept a string or an integer for id. Current impl expects a integer id

paging(params)

Takes the page parameter, converts the strings to ints and returns a new params object

parse_null_parameters(list)

Handy when parsing “null”‘s from query strings

parse_sort(sort_param)

Takes the sort parameter like -created_at,+name and turn it into something ecto’s order_by can use like [created_at: :desc, name: :asc]

split_filter_list(value)

Makes sure we don’t have nulls before spliting a filter list

Functions

clean_params(params)

Will take a standards string key => val params map and parse out useful pieces for JSONAPI.

This function is very much a work in progress, the most useful thing it currently does is call parse_sort/1 and paging/1 and return a atom => val map.

Source
get!(module, id)

Specs:

Gets the module from the current Repo raises JSONAPI.ResourceNotFound otherwise. Can accept a string or an integer for id. Current impl expects a integer id.

Source
paging(params)

Takes the page parameter, converts the strings to ints and returns a new params object.

Source
parse_null_parameters(list)

Handy when parsing “null”‘s from query strings.

Source
parse_sort(sort_param)

Takes the sort parameter like -created_at,+name and turn it into something ecto’s order_by can use like [created_at: :desc, name: :asc]

Source
split_filter_list(value)

Makes sure we don’t have nulls before spliting a filter list

Source