From dd925209bc89c64f936b50a1c85083b5a47f847e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20W=C3=B6ginger?= Date: Tue, 7 May 2024 22:22:20 +0200 Subject: [PATCH] WIP start with protocal for events todo * find a better name * missing user id for events * implement for all events * want to store also old content, ids etc. ? --- lib/radiator/event_store.ex | 9 +++++- lib/radiator/event_store/event_data.ex | 3 ++ lib/radiator/outline/event/abstract_event.ex | 30 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/radiator/outline/event/abstract_event.ex diff --git a/lib/radiator/event_store.ex b/lib/radiator/event_store.ex index eb732d4a..fb9f3235 100644 --- a/lib/radiator/event_store.ex +++ b/lib/radiator/event_store.ex @@ -5,9 +5,16 @@ defmodule Radiator.EventStore do alias Radiator.EventStore.EventData alias Radiator.Repo + alias Radiator.Outline.Event.AbstractEvent def persist_event(event) do - # persist event + {:ok, _stored_event} = + create_event_data(%{ + data: AbstractEvent.payload(event), + event_type: AbstractEvent.event_type(event), + uuid: AbstractEvent.event_id(event) + }) + event end diff --git a/lib/radiator/event_store/event_data.ex b/lib/radiator/event_store/event_data.ex index 81578f62..e85ae4b7 100644 --- a/lib/radiator/event_store/event_data.ex +++ b/lib/radiator/event_store/event_data.ex @@ -1,4 +1,7 @@ defmodule Radiator.EventStore.EventData do + @moduledoc """ + EventData schema represents a persistend event. + """ use Ecto.Schema import Ecto.Changeset diff --git a/lib/radiator/outline/event/abstract_event.ex b/lib/radiator/outline/event/abstract_event.ex new file mode 100644 index 00000000..899c351e --- /dev/null +++ b/lib/radiator/outline/event/abstract_event.ex @@ -0,0 +1,30 @@ +defprotocol Radiator.Outline.Event.AbstractEvent do + def payload(event) + def event_type(event) + def event_id(event) +end + +alias Radiator.Outline.Event.{NodeContentChangedEvent, NodeInsertedEvent} + +defimpl Radiator.Outline.Event.AbstractEvent, for: NodeInsertedEvent do + def payload(event) do + event.node + end + + def event_type(_event), do: "NodeInsertedEvent" + def event_id(event), do: event.event_id +end + +defimpl Radiator.Outline.Event.AbstractEvent, for: NodeContentChangedEvent do + def payload(event) do + event.node + end + + def event_type(_event), do: "NodeInsertedEvent" + def event_id(event), do: event.event_id +end + +# defmodule Radiator.Outline.Event.AbstractEvent do +# @callback payload(event :: any()) :: map() +# @callback event_type(event :: any()) :: String.t() +# end