Packages

Library used for integration with the rabbitmq for dispatching notification messages to consuming services.

Current section

Files

Jump to
notification_dispatcher lib schemas device.ex
Raw

lib/schemas/device.ex

defmodule NotificationDispatcher.Schema.Device do
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query, warn: false
alias NotificationDispatcher.Schema.Device
@primary_key {:id, :binary_id, autogenerate: true}
schema "devices" do
field :device_token, :string
field :user_id, :binary_id
field :os, :integer
timestamps()
end
@doc false
def changeset(device, attrs) do
device
|> cast(attrs, [:user_id, :device_token, :os])
|> validate_required([:user_id, :device_token, :os])
end
def changeset_update(device, attrs) do
device
|> cast(attrs, [:device_token])
|> validate_required([])
end
@doc false
def query_main, do: from(device in Device, as: :device)
def where(query, id), do: from([device: d] in query, where: d.id == ^id)
def where_user_id_in(query, user_ids), do: from([device: d] in query, where: d.user_id in ^user_ids)
end