2019-02-07 16:37:40 +01:00
|
|
|
import EctoEnum
|
|
|
|
|
|
|
|
defenum(Mobilizon.Events.ParticipantRoleEnum, :participant_role_type, [
|
|
|
|
:not_approved,
|
|
|
|
:participant,
|
|
|
|
:moderator,
|
|
|
|
:administrator,
|
|
|
|
:creator
|
|
|
|
])
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Events.Participant do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2018-05-18 09:56:21 +02:00
|
|
|
Represents a participant, an actor participating to an event
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.{Participant, Event}
|
|
|
|
alias Mobilizon.Actors.Actor
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
schema "participants" do
|
2019-02-07 16:37:40 +01:00
|
|
|
field(:role, Mobilizon.Events.ParticipantRoleEnum, default: :participant)
|
2018-07-27 10:45:35 +02:00
|
|
|
belongs_to(:event, Event, primary_key: true)
|
|
|
|
belongs_to(:actor, Actor, primary_key: true)
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Participant{} = participant, attrs) do
|
|
|
|
participant
|
2019-02-07 16:37:40 +01:00
|
|
|
|> Ecto.Changeset.cast(attrs, [:role, :event_id, :actor_id])
|
2018-05-18 09:56:21 +02:00
|
|
|
|> validate_required([:role, :event_id, :actor_id])
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
end
|