Skip to content

Commit

Permalink
Merge pull request #544 from podlove/task/refactor-abstract-event
Browse files Browse the repository at this point in the history
Refactor AbstractEvent module.
  • Loading branch information
electronicbites authored Jul 16, 2024
2 parents a47e945 + b513281 commit 9aecf25
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
6 changes: 3 additions & 3 deletions lib/radiator/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ defmodule Radiator.EventStore do
"""

alias Radiator.EventStore.EventData
alias Radiator.Outline.Event.AbstractEvent
alias Radiator.Outline.Event
alias Radiator.Repo

def persist_event(event) do
{:ok, _stored_event} =
create_event_data(%{
data: AbstractEvent.payload(event),
event_type: AbstractEvent.event_type(event),
data: Event.payload(event),
event_type: Event.event_type(event),
uuid: convert_to_uuid(event.uuid),
user_id: event.user_id
})
Expand Down
49 changes: 49 additions & 0 deletions lib/radiator/outline/event.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
defmodule Radiator.Outline.Event do
@moduledoc """
Event is a module that provides helper base functions do work with events.
"""

alias Radiator.Outline.Event.{
NodeContentChangedEvent,
NodeDeletedEvent,
NodeInsertedEvent,
NodeMovedEvent
}

def payload(%NodeInsertedEvent{} = event) do
%{
node_id: event.node.uuid,
content: event.node.content,
parent_id: event.node.parent_id,
prev_id: event.node.prev_id,
next_id: event.next_id
}
end

def payload(%NodeContentChangedEvent{} = event) do
%{node_id: event.node_id, content: event.content}
end

def payload(%NodeDeletedEvent{} = event) do
%{node_id: event.node_id}
end

def payload(%NodeMovedEvent{} = event) do
%{
node_id: event.node_id,
parent_id: event.parent_id,
prev_id: event.prev_id,
old_prev_id: event.old_prev_id,
old_next_id: event.old_next_id,
next_id: event.next_id
}
end

def event_type(%NodeInsertedEvent{} = _event), do: "NodeInsertedEvent"

def event_type(%NodeContentChangedEvent{} = _event), do: "NodeContentChangedEvent"

def event_type(%NodeDeletedEvent{} = _event), do: "NodeDeletedEvent"

def event_type(%NodeMovedEvent{} = _event), do: "NodeMovedEvent"
end
56 changes: 0 additions & 56 deletions lib/radiator/outline/event/abstract_event.ex

This file was deleted.

0 comments on commit 9aecf25

Please sign in to comment.