Last active
November 10, 2018 00:17
-
-
Save pedroassumpcao/99fef4c358c6e5b516222254a24ead5e to your computer and use it in GitHub Desktop.
Event Sourcing - Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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