2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.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
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Category
|
2018-11-06 10:30:27 +01:00
|
|
|
use Arc.Ecto.Schema
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
schema "categories" do
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:description, :string)
|
2018-11-06 10:30:27 +01:00
|
|
|
field(:picture, MobilizonWeb.Uploaders.Category.Type)
|
2018-07-27 10:45:35 +02: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-11-06 10:30:27 +01:00
|
|
|
|> cast(attrs, [:title, :description])
|
|
|
|
|> cast_attachments(attrs, [:picture])
|
2018-01-13 23:33:03 +01:00
|
|
|
|> validate_required([:title])
|
2017-12-08 09:58:14 +01:00
|
|
|
|> unique_constraint(:title)
|
|
|
|
end
|
|
|
|
end
|