2017-12-08 08:58:14 +00:00
|
|
|
defmodule Eventos.Events.Category do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
|
|
|
Represents a category for events
|
|
|
|
"""
|
2017-12-08 08:58:14 +00:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
alias Eventos.Events.Category
|
|
|
|
|
|
|
|
|
|
|
|
schema "categories" do
|
2018-01-13 22:33:03 +00:00
|
|
|
field :description, :string
|
2017-12-08 08:58:14 +00:00
|
|
|
field :picture, :string
|
2018-01-13 22:33:03 +00:00
|
|
|
field :title, :string, null: false
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Category{} = category, attrs) do
|
|
|
|
category
|
2018-01-13 22:33:03 +00:00
|
|
|
|> cast(attrs, [:title, :description, :picture])
|
|
|
|
|> validate_required([:title])
|
2017-12-08 08:58:14 +00:00
|
|
|
|> unique_constraint(:title)
|
|
|
|
end
|
|
|
|
end
|