Skip to content

Commit

Permalink
WIP start with protocal for events
Browse files Browse the repository at this point in the history
todo 
* find a better name
* missing user id for events
* implement for all events
* want to store also old content, ids etc. ?
  • Loading branch information
electronicbites committed May 7, 2024
1 parent 7dbb521 commit dd92520
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/radiator/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/radiator/event_store/event_data.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Radiator.EventStore.EventData do
@moduledoc """
EventData schema represents a persistend event.
"""
use Ecto.Schema
import Ecto.Changeset

Expand Down
30 changes: 30 additions & 0 deletions lib/radiator/outline/event/abstract_event.ex
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dd92520

Please sign in to comment.