debianize-mobilizon/lib/mobilizon/events/category.ex
Thomas Citharel b54dae7e15 Move to GraphQL
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2018-11-06 10:30:27 +01:00

27 lines
617 B
Elixir

defmodule Mobilizon.Events.Category do
@moduledoc """
Represents a category for events
"""
use Ecto.Schema
import Ecto.Changeset
alias Mobilizon.Events.Category
use Arc.Ecto.Schema
schema "categories" do
field(:description, :string)
field(:picture, MobilizonWeb.Uploaders.Category.Type)
field(:title, :string, null: false)
timestamps()
end
@doc false
def changeset(%Category{} = category, attrs) do
category
|> cast(attrs, [:title, :description])
|> cast_attachments(attrs, [:picture])
|> validate_required([:title])
|> unique_constraint(:title)
end
end