-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feature/mailer
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Fuschia.Entities.Nucleo do | ||
@moduledoc """ | ||
Nucleo schema | ||
""" | ||
use Fuschia.Schema | ||
import Ecto.Changeset | ||
|
||
@required_fields ~w(nome descricao)a | ||
@optional_fields ~w()a | ||
|
||
@primary_key {:nome, :string, []} | ||
schema "nucleo" do | ||
field :descricao, :string | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(%__MODULE__{} = struct, attrs) do | ||
struct | ||
|> cast(attrs, @required_fields ++ @optional_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_length(:descricao_nucleo, max: 400) | ||
end | ||
|
||
defimpl Jason.Encoder, for: __MODULE__ do | ||
def encode(struct, opts) do | ||
%{ | ||
nome: struct.nome, | ||
descricao_nucleo: struct.descricao_nucleo | ||
} | ||
|> Fuschia.Encoder.encode(opts) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Fuschia.Repo.Migrations.CreateNucleos do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:nucleo, primary_key: false) do | ||
add :nome, :string, primary_key: true | ||
add :descricao, :string, size: 400, null: false | ||
|
||
timestamps() | ||
end | ||
end | ||
end |