Skip to content

Instantly share code, notes, and snippets.

@pedroassumpcao
Last active November 10, 2018 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroassumpcao/99fef4c358c6e5b516222254a24ead5e to your computer and use it in GitHub Desktop.
Save pedroassumpcao/99fef4c358c6e5b516222254a24ead5e to your computer and use it in GitHub Desktop.
Event Sourcing - Command
defmodule Command.RegisterUser do
# Documentation and Typespec removed for brevity
use Ecto.Schema
import Ecto.Changeset
@primary_key false
embedded_schema do
field(:first_name)
field(:last_name)
field(:email)
field(:password)
end
def changeset(record, params \\ %{}) do
record
|> cast(params, __schema__(:fields))
|> validate_required(__schema__(:fields))
|> validate_format(:email, ~r/([\w.]+)@{1}([\w.]+)/)
|> validate_length(:password, min: 6)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment