35 lines
891 B
Elixir
35 lines
891 B
Elixir
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.
|
|
"""
|
|
|
|
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
|
|
end
|