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