Glific v0.3.1 Glific.Tags View Source

The Tags Context, which encapsulates and manages tags and the related join tables.

Link to this section Summary

Functions

Returns an %Ecto.Changeset{} for tracking contact changes.

Returns an %Ecto.Changeset{} for tracking message changes.

Returns an %Ecto.Changeset{} for tracking tag changes.

Return the count of tags, using the same filter as list_tags

Creates a message tag

Creates a tag.

Creates a template tag.

Deletes a contact tag.

Deletes a list of contact tags, each tag attached to the same contact

Deletes a message tag.

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids. We will generalize this function and move it to Repo.ex when we get a better handle on how to do so :)

Deletes a tag.

Deletes a list of template tags, each tag attached to the same template

Gets a single contact.

Gets a single message.

Gets a single tag.

Given a tag id or a list of tag ids, retrieve all the ancestors for the list_tags

Converts all tag kewords into the map where keyword is the key and tag id is the value

Returns the list of tags.

Remove a specific tag from contact messages

Filter all the status tag and returns as a map

Updates a tag.

Link to this section Functions

Link to this function

change_contact_tag(contact_tag, attrs \\ %{})

View Source

Specs

change_contact_tag(Glific.Tags.ContactTag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking contact changes.

Examples

iex> change_contact_tag(contact_tag)
%Ecto.Changeset{data: %ContactTag{}}
Link to this function

change_message_tag(message_tag, attrs \\ %{})

View Source

Specs

change_message_tag(Glific.Tags.MessageTag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking message changes.

Examples

iex> change_message_tag(message_tag)
%Ecto.Changeset{data: %MessageTag{}}
Link to this function

change_tag(tag, attrs \\ %{})

View Source

Specs

change_tag(Glific.Tags.Tag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking tag changes.

Examples

iex> change_tag(tag)
%Ecto.Changeset{data: %Tag{}}

Specs

count_tags(map()) :: integer()

Return the count of tags, using the same filter as list_tags

Link to this function

create_contact_tag(attrs \\ %{})

View Source

Specs

create_contact_tag(map()) ::
  {:ok, Glific.Tags.ContactTag.t()} | {:error, Ecto.Changeset.t()}

Creates a contact.

Examples

iex> create_contact_tag(%{field: value})
{:ok, %Contact{}}

iex> create_contact_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_message_tag(attrs \\ %{})

View Source

Specs

create_message_tag(map()) ::
  {:ok, Glific.Tags.MessageTag.t()} | {:error, Ecto.Changeset.t()}

Creates a message tag

Examples

iex> create_message_tag(%{field: value}) {:ok, %Message{}}

iex> create_message_tag(%{field: bad_value}) {:error, %Ecto.Changeset{}}

Specs

create_tag(map()) :: {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Creates a tag.

Examples

iex> create_tag(%{field: value})
{:ok, %Tag{}}

iex> create_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_template_tag(attrs \\ %{})

View Source

Specs

create_template_tag(map()) ::
  {:ok, Glific.Tags.TemplateTag.t()} | {:error, Ecto.Changeset.t()}

Creates a template tag.

Examples

iex> create_template_tag(%{field: value})
{:ok, %Contact{}}

iex> create_template_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_contact_tag(contact_tag)

View Source

Specs

delete_contact_tag(Glific.Tags.ContactTag.t()) ::
  {:ok, Glific.Tags.ContactTag.t()} | {:error, Ecto.Changeset.t()}

Deletes a contact tag.

Examples

iex> delete_contact_tag(contact_tag)
{:ok, %ContactTag{}}

iex> delete_contact_tag(contact_tag)
{:error, %Ecto.Changeset{}}
Link to this function

delete_contact_tag_by_ids(contact_id, tag_ids)

View Source

Specs

delete_contact_tag_by_ids(integer(), []) :: {integer(), nil | [term()]}

Deletes a list of contact tags, each tag attached to the same contact

Link to this function

delete_message_tag(message_tag)

View Source

Specs

delete_message_tag(Glific.Tags.MessageTag.t()) ::
  {:ok, Glific.Tags.MessageTag.t()} | {:error, Ecto.Changeset.t()}

Deletes a message tag.

Examples

iex> delete_message_tag(message_tag)
{:ok, %MessageTag{}}

iex> delete_message_tag(message_tag)
{:error, %Ecto.Changeset{}}
Link to this function

delete_message_tag_by_ids(message_id, tag_ids)

View Source

Specs

delete_message_tag_by_ids(integer(), []) :: {integer(), nil | [term()]}

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids. We will generalize this function and move it to Repo.ex when we get a better handle on how to do so :)

Specs

delete_tag(Glific.Tags.Tag.t()) ::
  {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Deletes a tag.

Examples

iex> delete_tag(tag)
{:ok, %Tag{}}

iex> delete_tag(tag)
{:error, %Ecto.Changeset{}}
Link to this function

delete_template_tag_by_ids(template_id, tag_ids)

View Source

Specs

delete_template_tag_by_ids(integer(), []) :: {integer(), nil | [term()]}

Deletes a list of template tags, each tag attached to the same template

Specs

get_contact_tag!(integer()) :: Glific.Tags.ContactTag.t()

Gets a single contact.

Raises Ecto.NoResultsError if the Contact does not exist.

Examples

iex> get_contact_tag!(123)
%Contact{}

iex> get_contact_tag!(456)
** (Ecto.NoResultsError)

Specs

get_message_tag!(integer()) :: Glific.Tags.MessageTag.t()

Gets a single message.

Raises Ecto.NoResultsError if the Message does not exist.

Examples

iex> get_message_tag!(123)
%Message{}

iex> get_message_tag!(456)
** (Ecto.NoResultsError)

Specs

get_tag!(integer()) :: Glific.Tags.Tag.t()

Gets a single tag.

Raises Ecto.NoResultsError if the Tag does not exist.

Examples

iex> get_tag!(123)
%Tag{}

iex> get_tag!(456)
** (Ecto.NoResultsError)
Link to this function

include_all_ancestors(tag_id)

View Source

Specs

include_all_ancestors(non_neg_integer() | [non_neg_integer()]) :: [
  non_neg_integer()
]

Given a tag id or a list of tag ids, retrieve all the ancestors for the list_tags

Specs

keyword_map(map()) :: map()

Converts all tag kewords into the map where keyword is the key and tag id is the value

Specs

list_tags(map()) :: [Glific.Tags.Tag.t()]

Returns the list of tags.

Examples

iex> list_tags()
[%Tag{}, ...]
Link to this function

remove_tag_from_all_message(contact_id, tag_shortcode)

View Source

Specs

remove_tag_from_all_message(integer(), String.t()) :: list()
remove_tag_from_all_message(integer(), [String.t()]) :: list()

Remove a specific tag from contact messages

Specs

status_map(map()) :: %{required(String.t()) => integer()}

Filter all the status tag and returns as a map

Link to this function

update_contact_tag(contact_tag, attrs)

View Source

Specs

update_contact_tag(Glific.Tags.ContactTag.t(), map()) ::
  {:ok, Glific.Tags.ContactTag.t()} | {:error, Ecto.Changeset.t()}

Updates a contact tag.

Examples

iex> update_contact_tag(contact_tag, %{field: new_value})
{:ok, %ContactTag{}}

iex> update_contact_tag(contact_tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_message_tag(message_tag, attrs)

View Source

Specs

update_message_tag(Glific.Tags.MessageTag.t(), map()) ::
  {:ok, Glific.Tags.MessageTag.t()} | {:error, Ecto.Changeset.t()}

Updates a message tag.

Examples

iex> update_message_tag(message_tag, %{field: new_value})
{:ok, %MessageTag{}}

iex> update_message_tag(message_tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}

Specs

update_tag(Glific.Tags.Tag.t(), map()) ::
  {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Updates a tag.

Examples

iex> update_tag(tag, %{field: new_value})
{:ok, %Tag{}}

iex> update_tag(tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}