View Source ExTeal.Resource.Index behaviour (ExTeal v0.27.0)
Behavior for handling index requests for a given resource
Summary
Callbacks
Returns the actions available for a resource
Returns the models to be represented by this resource.
Returns the models to be represented by this resource via a relationship.
Defines the search adapter to use while building a search query
Functions
Callback implementation for ExTeal.Resource.Repo.repo/0
.
Callbacks
@callback actions(Plug.Conn.t()) :: [module()]
Returns the actions available for a resource
Default implementation is an empty array.
@callback handle_index(Plug.Conn.t(), map()) :: Plug.Conn.t() | ExTeal.records()
Returns the models to be represented by this resource.
Default implementation is the result of the ExTeal.Resource.Records.records/2
callback. Usually a module or an %Ecto.Query{}
.
The results of this callback are passed to the filter and sort callbacks before the query is executed.
handle_index/2
can alternatively return a conn with any response/body.
Example custom implementation:
def handle_index(conn, _params) do
case conn.assigns[:current_user] do
nil -> App.Post
user -> User.own_posts(user)
end
end
In most cases ExTeal.Resource.Records.records/1, filter/4, and sort/4 are the better customization hooks.
@callback search_adapter(Ecto.Query.t(), module(), map()) :: Ecto.Query.t()
Defines the search adapter to use while building a search query:
Defaults to the ExTeal.Search.SimpleSearch
module