2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Events.Track do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2019-09-13 01:01:17 +02:00
|
|
|
Represents a track for an event (such as a theme) having multiple sessions.
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
use Ecto.Schema
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
import Ecto.Changeset
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2019-09-13 01:55:45 +02:00
|
|
|
alias Mobilizon.Events.{Event, Session}
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
color: String.t(),
|
|
|
|
description: String.t(),
|
|
|
|
name: String.t(),
|
|
|
|
event: Event.t(),
|
|
|
|
sessions: [Session.t()]
|
|
|
|
}
|
|
|
|
|
|
|
|
@required_attrs [:name, :description, :color]
|
|
|
|
@optional_attrs [:event_id]
|
|
|
|
@attrs @required_attrs ++ @optional_attrs
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
schema "tracks" do
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:color, :string)
|
|
|
|
field(:description, :string)
|
|
|
|
field(:name, :string)
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
belongs_to(:event, Event)
|
|
|
|
has_many(:sessions, Session)
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2019-09-13 01:55:45 +02:00
|
|
|
def changeset(%__MODULE__{} = track, attrs) do
|
2018-01-13 23:33:03 +01:00
|
|
|
track
|
2019-09-13 01:01:17 +02:00
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
end
|