debianize-mobilizon/lib/mobilizon/events/event_options.ex

80 lines
2.3 KiB
Elixir
Raw Normal View History

2019-09-13 01:01:17 +02:00
defmodule Mobilizon.Events.EventOptions do
@moduledoc """
2019-09-13 01:01:17 +02:00
Represents an event options.
"""
use Ecto.Schema
2019-09-13 01:01:17 +02:00
import Ecto.Changeset
alias Mobilizon.Discussions.CommentModeration
alias Mobilizon.Events.{
EventOffer,
2019-09-22 16:26:23 +02:00
EventParticipationCondition
}
2019-09-13 01:01:17 +02:00
@type t :: %__MODULE__{
maximum_attendee_capacity: integer,
remaining_attendee_capacity: integer,
show_remaining_attendee_capacity: boolean,
anonymous_participation: boolean,
2019-09-13 01:01:17 +02:00
attendees: [String.t()],
program: String.t(),
comment_moderation: CommentModeration.t(),
show_participation_price: boolean,
offers: [EventOffer.t()],
participation_condition: [EventParticipationCondition.t()],
show_start_time: boolean,
show_end_time: boolean,
timezone: String.t() | nil,
hide_organizer_when_group_event: boolean,
is_online: boolean()
2019-09-13 01:01:17 +02:00
}
@attrs [
:maximum_attendee_capacity,
:remaining_attendee_capacity,
:show_remaining_attendee_capacity,
:anonymous_participation,
2019-09-13 01:01:17 +02:00
:attendees,
:program,
:comment_moderation,
:show_participation_price,
:show_start_time,
:show_end_time,
:timezone,
:hide_organizer_when_group_event,
:is_online
2019-09-13 01:01:17 +02:00
]
@primary_key false
@derive Jason.Encoder
embedded_schema do
field(:maximum_attendee_capacity, :integer)
field(:remaining_attendee_capacity, :integer)
field(:show_remaining_attendee_capacity, :boolean)
field(:anonymous_participation, :boolean)
field(:attendees, {:array, :string})
field(:program, :string)
field(:comment_moderation, CommentModeration)
field(:show_participation_price, :boolean)
field(:show_start_time, :boolean, default: true)
field(:show_end_time, :boolean, default: true)
field(:timezone, :string)
field(:hide_organizer_when_group_event, :boolean, default: false)
field(:is_online, :boolean, default: false)
2019-09-13 01:01:17 +02:00
embeds_many(:offers, EventOffer)
embeds_many(:participation_condition, EventParticipationCondition)
end
2019-09-13 01:01:17 +02:00
@doc false
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
2019-09-13 01:55:45 +02:00
def changeset(%__MODULE__{} = event_options, attrs) do
event_options
|> cast(attrs, @attrs)
|> validate_number(:maximum_attendee_capacity, greater_than_or_equal_to: 0)
end
end