mobilizon.chapril.org-mobil.../lib/mobilizon/admin/admin.ex

36 lines
842 B
Elixir
Raw Normal View History

defmodule Mobilizon.Admin do
@moduledoc """
The Admin context.
"""
2019-09-08 01:49:56 +02:00
import Ecto.Query
alias Mobilizon.Admin.ActionLog
2019-09-08 01:49:56 +02:00
alias Mobilizon.Storage.{Page, Repo}
@doc """
Creates a action_log.
"""
2019-09-08 02:06:28 +02:00
@spec create_action_log(map) :: {:ok, ActionLog.t()} | {:error, Ecto.Changeset.t()}
def create_action_log(attrs \\ %{}) do
%ActionLog{}
|> ActionLog.changeset(attrs)
|> Repo.insert()
end
2019-09-08 02:06:28 +02:00
2019-09-09 00:52:49 +02:00
@doc """
Returns the list of action logs.
"""
@spec list_action_logs(integer | nil, integer | nil) :: [ActionLog.t()]
def list_action_logs(page \\ nil, limit \\ nil) do
list_action_logs_query()
|> Page.paginate(page, limit)
|> Repo.all()
end
2019-09-08 02:06:28 +02:00
@spec list_action_logs_query :: Ecto.Query.t()
defp list_action_logs_query do
from(r in ActionLog, preload: [:actor], order_by: [desc: :id])
2019-09-08 02:06:28 +02:00
end
end