Skip to content

Commit

Permalink
Create restaurant model
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Sep 28, 2021
1 parent 8e4f0b6 commit c13946c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/inmana/restaurant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down

0 comments on commit c13946c

Please sign in to comment.