diff --git a/lib/inmana/restaurant.ex b/lib/inmana/restaurant.ex index f0fa5db..59af4ae 100644 --- a/lib/inmana/restaurant.ex +++ b/lib/inmana/restaurant.ex @@ -4,6 +4,10 @@ defmodule Inmana.Restaurant do @primary_key {:id, :binary_id, autogenerate: true} + @required_params [:email, :name] + + @derive {Jason.Encoder, only: @required_params ++ [:id]} + schema "restaurants" do field :email, :string field :name, :string @@ -13,8 +17,8 @@ defmodule Inmana.Restaurant do def changeset(params) do %__MODULE__{} - |> cast(params, [:email, :name]) - |> validate_required([:email, :name]) + |> cast(params, @required_params) + |> validate_required(@required_params) |> validate_length(:name, min: 2) |> validate_format(:email, ~r/@/) |> unique_constraint([:email])