2018-10-11 15:37:39 +00:00
|
|
|
defmodule Mobilizon.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
|
2018-10-11 15:37:39 +00:00
|
|
|
alias Mobilizon.Events.Category
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
schema "categories" do
|
2018-07-27 08:45:35 +00:00
|
|
|
field(:description, :string)
|
|
|
|
field(:picture, :string)
|
|
|
|
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
|