View Source Filterable.Phoenix.Controller (Filterable v0.7.5)

Allows to extend Phoenix controller with filterable macros and functions.

use Filterable.Phoenix.Controller

Example:

defmodule MyApp.PostController do
  use MyApp.Web, :controller
  use Filterable.Phoenix.Controller

  filterable do
    filter author(query, value, _conn) do
      query |> where(author_name: ^value)
    end
  end

  # /posts?author=Kafka
  def index(conn, params) do
    with {:ok, query, filter_values} <- apply_filters(Post, conn),
         posts                       <- Repo.all(query),
     do: render(conn, "index.json", posts: posts, meta: filter_values)
  end
end