tusker_push/lib/tusker_push.ex

35 lines
891 B
Elixir
Raw Normal View History

2024-04-05 18:23:00 +00:00
defmodule TuskerPush do
@moduledoc """
TuskerPush keeps the contexts that define your domain
and business logic.
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""
2024-04-05 19:04:38 +00:00
alias TuskerPush.Registration
alias TuskerPush.Repo
@spec register(Map.t()) ::
{:ok, Registration.t()} | {:error, Ecto.Changeset.t()}
def register(params) do
params
|> Registration.create_changeset()
|> Repo.insert()
end
@spec unregister(String.t()) :: :ok | {:error, :no_registration | Ecto.Changeset.t()}
def unregister(id) do
with registration when not is_nil(registration) <- Repo.get(Registration, id),
{:ok, _} <- Repo.delete(registration) do
:ok
else
nil ->
{:error, :no_registration}
{:error, reason} ->
{:error, reason}
end
end
2024-04-05 18:23:00 +00:00
end