Allow to add metadata to an event
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -103,6 +103,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
field(:updated_at, :datetime, description: "When the event was last updated")
|
||||
field(:inserted_at, :datetime, description: "When the event was created")
|
||||
field(:options, :event_options, description: "The event options")
|
||||
field(:metadata, list_of(:event_metadata), description: "A key-value list of metadata")
|
||||
end
|
||||
|
||||
@desc "The list of visibility options for an event"
|
||||
@@ -290,6 +291,26 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
)
|
||||
end
|
||||
|
||||
enum :event_metadata_type do
|
||||
value(:string, description: "A string")
|
||||
value(:integer, description: "An integer")
|
||||
value(:boolean, description: "A boolean")
|
||||
end
|
||||
|
||||
object :event_metadata do
|
||||
field(:key, :string, description: "The key for the metadata")
|
||||
field(:title, :string, description: "The title for the metadata")
|
||||
field(:value, :string, description: "The value for the metadata")
|
||||
field(:type, :event_metadata_type, description: "The metadata type")
|
||||
end
|
||||
|
||||
input_object :event_metadata_input do
|
||||
field(:key, non_null(:string), description: "The key for the metadata")
|
||||
field(:title, :string, description: "The title for the metadata")
|
||||
field(:value, non_null(:string), description: "The value for the metadata")
|
||||
field(:type, :event_metadata_type, description: "The metadata type")
|
||||
end
|
||||
|
||||
@desc """
|
||||
A event contact
|
||||
"""
|
||||
@@ -372,6 +393,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
arg(:category, :string, default_value: "meeting", description: "The event's category")
|
||||
arg(:physical_address, :address_input, description: "The event's physical address")
|
||||
arg(:options, :event_options_input, description: "The event options")
|
||||
arg(:metadata, list_of(:event_metadata_input), description: "The event metadata")
|
||||
|
||||
arg(:draft, :boolean,
|
||||
default_value: false,
|
||||
@@ -419,6 +441,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
arg(:category, :string, description: "The event's category")
|
||||
arg(:physical_address, :address_input, description: "The event's physical address")
|
||||
arg(:options, :event_options_input, description: "The event options")
|
||||
arg(:metadata, list_of(:event_metadata_input), description: "The event metadata")
|
||||
arg(:draft, :boolean, description: "Whether or not the event is a draft")
|
||||
arg(:contacts, list_of(:contact), default_value: [], description: "The events contacts")
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ defmodule Mobilizon.Events.Event do
|
||||
alias Mobilizon.Discussions.Comment
|
||||
|
||||
alias Mobilizon.Events.{
|
||||
EventMetadata,
|
||||
EventOptions,
|
||||
EventParticipantStats,
|
||||
EventStatus,
|
||||
@@ -108,6 +109,7 @@ defmodule Mobilizon.Events.Event do
|
||||
|
||||
embeds_one(:options, EventOptions, on_replace: :delete)
|
||||
embeds_one(:participant_stats, EventParticipantStats, on_replace: :update)
|
||||
embeds_many(:metadata, EventMetadata, on_replace: :delete)
|
||||
belongs_to(:organizer_actor, Actor, foreign_key: :organizer_actor_id)
|
||||
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
||||
belongs_to(:physical_address, Address, on_replace: :nilify)
|
||||
@@ -151,6 +153,7 @@ defmodule Mobilizon.Events.Event do
|
||||
defp common_changeset(%Changeset{} = changeset, attrs) do
|
||||
changeset
|
||||
|> cast_embed(:options)
|
||||
|> cast_embed(:metadata)
|
||||
|> put_assoc(:contacts, Map.get(attrs, :contacts, []))
|
||||
|> put_assoc(:media, Map.get(attrs, :media, []))
|
||||
|> put_tags(attrs)
|
||||
|
||||
45
lib/mobilizon/events/event_metadata.ex
Normal file
45
lib/mobilizon/events/event_metadata.ex
Normal file
@@ -0,0 +1,45 @@
|
||||
defmodule Mobilizon.Events.EventMetadata do
|
||||
@moduledoc """
|
||||
Participation stats on event
|
||||
"""
|
||||
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
import EctoEnum
|
||||
|
||||
defenum(EventMetadataTypeEnum, string: 0, integer: 1, boolean: 2)
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
key: String.t(),
|
||||
value: String.t()
|
||||
}
|
||||
|
||||
@required_attrs [
|
||||
:key,
|
||||
:value
|
||||
]
|
||||
|
||||
@optional_attrs [
|
||||
:title,
|
||||
:type
|
||||
]
|
||||
|
||||
@attrs @required_attrs ++ @optional_attrs
|
||||
|
||||
@primary_key false
|
||||
@derive Jason.Encoder
|
||||
embedded_schema do
|
||||
field(:key, :string)
|
||||
field(:title, :string)
|
||||
field(:value, :string)
|
||||
field(:type, EventMetadataTypeEnum, default: :string)
|
||||
end
|
||||
|
||||
@doc false
|
||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||
def changeset(%__MODULE__{} = event_metadata, attrs) do
|
||||
event_metadata
|
||||
|> cast(attrs, @attrs)
|
||||
|> validate_required(@required_attrs)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user