Created
May 28, 2023 14:58
-
-
Save mazz/db84e847b13111062f4e1e04b26b0974 to your computer and use it in GitHub Desktop.
channel.ex
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
@required_fields [ | |
:name, | |
:org_id, | |
:owner_id, | |
:channel_category_id, | |
:slug, | |
:item_ids | |
] | |
@optional_fields [:visibility, :ordinality, :slug, :poster_path, :description, :content_type] | |
def validate_name(changeset) do | |
changeset | |
|> ChangesetExt.ensure_trimmed(:name) | |
|> validate_required([:name]) | |
|> validate_length(:name, min: 2, max: 160) | |
end | |
@doc false | |
def changeset(channel, attrs) do | |
channel | |
|> cast(attrs, @required_fields ++ @optional_fields) | |
|> validate_name() | |
|> validate_required(@required_fields) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment