2019-07-23 13:49:22 +02:00
|
|
|
defmodule Mobilizon.Admin do
|
|
|
|
@moduledoc """
|
|
|
|
The Admin context.
|
|
|
|
"""
|
|
|
|
|
2019-09-08 01:49:56 +02:00
|
|
|
import Ecto.Query
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
alias Mobilizon.Admin.ActionLog
|
2019-09-08 01:49:56 +02:00
|
|
|
alias Mobilizon.Storage.{Page, Repo}
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
@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()}
|
2019-07-23 13:49:22 +02:00
|
|
|
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
|
2019-09-21 23:59:07 +02:00
|
|
|
from(r in ActionLog, preload: [:actor], order_by: [desc: :id])
|
2019-09-08 02:06:28 +02:00
|
|
|
end
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|