defmodule NotificationDispatcher.Context.NotificationsContext do @moduledoc """ The Notifications context. """ import Ecto.Query, warn: false def get_repo(), do: Application.fetch_env!(:notification_dispatcher, :repo) alias NotificationDispatcher.Schema.NotificationMessage def get_notification_message!(id), do: get_repo().get!(NotificationMessage, id) def get_one_notification_message!(channel) do NotificationMessage.query_main() |> NotificationMessage.where_channel(channel) |> NotificationMessage.limit(1) |> get_repo().one() end def get_by_type_and_language(type, language) do NotificationMessage.query_main() |> NotificationMessage.where_type(type) |> NotificationMessage.where_locale(language) |> NotificationMessage.limit(1) |> get_repo().one() end def get_by_type(type) do NotificationMessage.query_main() |> NotificationMessage.where_type(type) |> NotificationMessage.limit(1) |> get_repo().one() end def create_notification_message(attrs \\ %{}) do %NotificationMessage{} |> NotificationMessage.changeset(attrs) |> get_repo().insert() end def delete_notification_message(%NotificationMessage{} = notification_message) do get_repo().delete(notification_message) end end