2018-01-13 23:33:03 +01:00
|
|
|
defmodule Eventos.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
|
|
|
|
alias Eventos.Events.{Participant, Event}
|
2018-05-18 09:56:21 +02:00
|
|
|
alias Eventos.Actors.Actor
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
schema "participants" do
|
2018-06-06 17:42:53 +02:00
|
|
|
field :role, :integer, default: 0 # 0 : participant, 1 : moderator, 2 : administrator, 3 : creator
|
2018-05-18 09:56:21 +02:00
|
|
|
field :approved, :boolean
|
2018-01-13 23:33:03 +01:00
|
|
|
belongs_to :event, Event, primary_key: true
|
2018-05-18 09:56:21 +02:00
|
|
|
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
|