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0.0.3
0.0.2
0.0.1
Step flow manager for Elixir applications
Current section
Files
Jump to
Current section
Files
lib/step_flow/notification_hooks/notification_templates.ex
defmodule StepFlow.NotificationHooks.NotificationTemplates do
@moduledoc """
The Notification templates context.
"""
import Ecto.Query, warn: false
alias StepFlow.NotificationHooks.NotificationTemplate
alias StepFlow.Repo
defp force_integer(param) when is_bitstring(param) do
param
|> String.to_integer()
end
defp force_integer(param) do
param
end
@doc """
Returns the list of notification templates.
## Examples
iex> list_notification_templates()
[%NotificationTemplate{}, ...]
"""
def list_notification_templates(params \\ %{}) do
page =
Map.get(params, "page", 0)
|> force_integer
size =
Map.get(params, "size", 100)
|> force_integer
offset = page * size
query = from(notification_template in NotificationTemplate)
query =
case Map.get(params, "template_name") do
nil ->
query
template_name ->
from(notification_template in query,
where: notification_template.template_name == ^template_name
)
end
total = Repo.aggregate(query, :count)
query =
from(
notification_template in query,
order_by: [desc: :template_name],
offset: ^offset,
limit: ^size
)
notification_templates = Repo.all(query)
%{
data: notification_templates,
total: total,
page: page,
size: size
}
end
@doc """
Gets a single notification_template.
Raises `Ecto.NoResultsError` if the notification_template does not exist.
## Examples
iex> get_notification_template!(123)
%NotificationTemplate{}
iex> get_notification_template!(456)
** (Ecto.NoResultsError)
"""
def get_notification_template!(id), do: Repo.get!(NotificationTemplate, id)
@doc """
Gets a single notification_template by template_name.
## Examples
iex> get_notification_template_by_name("MY_NAME")
%NotificationTemplate{}
iex> get_notification_template_by_name("BAD_NAME")
nil
"""
def get_notification_template_by_name(template_name),
do: Repo.get_by(NotificationTemplate, template_name: template_name)
@doc """
Creates a notification_template.
## Examples
iex> create_notification_template(%
{
template_name: template_name_value,
template_headers: template_headers_value,
template_body: template_body_value
})
{:ok, %NotificationTemplate{}}
iex> create_notification_template(%
{
template_name: duplicate_template_name_value,
template_headers: template_headers_value,
template_body: template_body_value
})
{:error, %Ecto.Changeset{}}
"""
def create_notification_template(attrs \\ %{}) do
%NotificationTemplate{}
|> NotificationTemplate.changeset(attrs)
|> Repo.insert()
end
@doc """
Deletes a NotificationTemplate.
## Examples
iex> delete_notification_template(notification_template)
{:ok, %NotificationTemplate{}}
iex> delete_notification_template(notification_template)
{:error, %Ecto.Changeset{}}
"""
def delete_notification_template(%NotificationTemplate{} = notification_template) do
Repo.delete(notification_template)
end
@doc """
Updates NotificationTemplate.
## Examples
iex> update_notification_template(notification_template, %{field: new_value})
{:ok, %NotificationTemplate{}}
iex> update_notification_template(notification_template, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_notification_template(%NotificationTemplate{} = notification_template, attrs) do
notification_template
|> NotificationTemplate.changeset(attrs)
|> Repo.update()
end
end