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
|
2018-07-27 10:45:35 +02:00
|
|
|
# 0 : not_approved, 1 : participant, 2 : moderator, 3 : administrator, 4 : creator
|
|
|
|
field(:role, :integer, default: 0)
|
|
|
|
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
|
2018-05-18 09:56:21 +02:00
|
|
|
|> cast(attrs, [:role, :event_id, :actor_id])
|
|
|
|
|> validate_required([:role, :event_id, :actor_id])
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
end
|