-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
528 additions
and
469 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
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
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,28 @@ | ||
defmodule Athena.ChangesetHelper do | ||
@moduledoc false | ||
|
||
import Ecto.Changeset | ||
|
||
alias Ecto.Changeset | ||
|
||
@spec fill_uuid(changeset :: Changeset.t()) :: Changeset.t() | ||
def fill_uuid(changeset) do | ||
changeset | ||
|> fetch_field!(:id) | ||
|> case do | ||
nil -> put_change(changeset, :id, Ecto.UUID.generate()) | ||
id when is_binary(id) -> changeset | ||
end | ||
end | ||
|
||
@spec validate_one_required(changeset :: Changeset.t(), fields :: [atom()]) :: Changeset.t() | ||
def validate_one_required(changeset, [first_field | _] = fields) do | ||
fields | ||
|> Enum.map(&get_field(changeset, &1)) | ||
|> Enum.reject(&is_nil/1) | ||
|> case do | ||
[] -> add_error(changeset, first_field, "at least field is required", fields: fields) | ||
[_ | _] -> changeset | ||
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.