Verified Commit 8862a8cf authored by Nicolas's avatar Nicolas

Refactor event repo modules

parent 6fdd7ff6
......@@ -19,7 +19,7 @@ defmodule PlasmaRepo.Application do
max_seconds: 1
]},
{Task.Supervisor, name: PlasmaRepo.TaskSupervisor},
PlasmaRepo.Channels.EventTypeCache,
PlasmaRepo.Events.EventTypeCache,
PlasmaRepo.Auth.AccessTokenCache,
# Start the Ecto repository
PlasmaRepo.Repo
......
defmodule PlasmaRepo.Channels.Event do
defmodule PlasmaRepo.Events.Event do
use PlasmaRepo.Schema
alias PlasmaRepo.Channels.{Channel, Event, EventContent}
alias PlasmaRepo.Channels.EventType
alias PlasmaRepo.Channels.Identifier
alias PlasmaRepo.Events.{Event, EventContent}
alias PlasmaRepo.Events.EventType
alias PlasmaRepo.Events.Identifier
alias PlasmaRepo.Repo
@type t :: %__MODULE__{
......@@ -52,7 +52,7 @@ defmodule PlasmaRepo.Channels.Event do
|> foreign_key_constraint(:event_type_id)
|> put_assoc(
:content,
PlasmaRepo.Channels.EventContent.create_changeset(%PlasmaRepo.Channels.EventContent{}, attrs)
EventContent.create_changeset(%EventContent{}, attrs)
)
end
......
defmodule PlasmaRepo.Channels.EventContent do
defmodule PlasmaRepo.Events.EventContent do
use PlasmaRepo.Schema
alias PlasmaRepo.Channels.Event
alias PlasmaRepo.Events.Event
schema "event_contents" do
field :content, :any, virtual: true
......
defmodule PlasmaRepo.Channels.EventType do
defmodule PlasmaRepo.Events.EventType do
require Logger
use PlasmaRepo.Schema
alias PlasmaRepo.Channels.EventType
alias PlasmaRepo.Channels.EventTypeCachableRepo
alias PlasmaRepo.Events.EventType
alias PlasmaRepo.Events.EventTypeCachableRepo
schema "event_types" do
field :name, :string
timestamps(updated_at: false)
end
defp create_changeset(event_type, attrs) do
......
defmodule PlasmaRepo.Channels.EventTypeCache do
defmodule PlasmaRepo.Events.EventTypeCache do
use Nebulex.Cache,
otp_app: :plasma,
adapter: Nebulex.Adapters.Local
end
defmodule PlasmaRepo.Channels.EventTypeCachableRepo do
defmodule PlasmaRepo.Events.EventTypeCachableRepo do
use NebulexEcto.Repo,
cache: PlasmaRepo.Channels.EventTypeCache,
cache: PlasmaRepo.Events.EventTypeCache,
repo: PlasmaRepo.Repo
end
defmodule PlasmaRepo.Channels.Events do
defmodule PlasmaRepo.Events.Events do
require Logger
alias PlasmaRepo.Repo
alias PlasmaRepo.Channels.Channel
alias PlasmaRepo.Channels.Event
alias PlasmaRepo.Events.Event
@doc """
Add a list of event to a channel.
......
......@@ -3,7 +3,7 @@ defmodule PlasmaRepo.MatrixRooms.CommandHandler do
require Logger
require PlasmaRepo.MatrixRooms.EventTypes
alias PlasmaRepo.MatrixRooms.Commands.{CreateRoom, ChangeJoinRules, AddStateEvent}
alias PlasmaRepo.Channels.Event
alias PlasmaRepo.Events.Event
alias PlasmaRepo.MatrixRooms.EventTypes
@matrix_config Application.get_env(:repo, :matrix)
......
......@@ -21,7 +21,7 @@ defmodule PlasmaHS.Application do
PlasmaHS.Plugs.AuthSessionCache.Primary,
# Start the endpoint when the application starts
PlasmaHS.Endpoint,
PlasmaRepo.Channels.EventTypeCache,
PlasmaRepo.Events.EventTypeCache,
PlasmaRepo.Users.AccessTokenCache,
# Start the Ecto repository
PlasmaRepo.Repo
......
......@@ -4,6 +4,7 @@ defmodule Plasma.Repo.Migrations.CreateEventTypeTable do
def change do
create table(:event_types) do
add :name, :string, null: false
timestamps(updated_at: false)
end
create unique_index(:event_types, [:name])
......
......@@ -4,7 +4,7 @@ defmodule Plasma.ChannelsTest do
alias PlasmaRepo.Channels.Identifier
def clear_cache(_context) do
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
defmodule Plasma.Model.EventTest do
defmodule PlasmaRepo.Events.EventTest do
use PlasmaRepo.DataCase
alias PlasmaRepo.Channels.EventType
alias PlasmaRepo.Events.EventType
alias PlasmaRepo.Channels
alias PlasmaRepo.Channels.Event
alias PlasmaRepo.Events.Event
def clear_cache(_context) do
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
defmodule Plasma.Model.EventTypesTest do
defmodule PlasmaRepo.Events.EventTypesTest do
use PlasmaRepo.DataCase
alias PlasmaRepo.Channels.EventType
alias PlasmaRepo.Events.EventType
import PlasmaRepo.Factory
def clear_cache(_context) do
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
defmodule Plasma.EventsTest do
defmodule PlasmaRepo.Events.EventsTest do
use PlasmaRepo.DataCase
alias PlasmaRepo.Channels.Events
alias PlasmaRepo.Events.Events
alias PlasmaRepo.Channels.Identifier
def clear_cache(_context) do
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
......@@ -4,7 +4,7 @@ defmodule PlasmaWeb.Controllers.MatrixApi.Client.AccountTest do
def clear_cache(_context) do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
......@@ -5,7 +5,7 @@ defmodule PlasmaWeb.Controllers.MatrixApi.Client.LoginTest do
def clear_cache(_context) do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
......@@ -5,7 +5,7 @@ defmodule PlasmaWeb.Controllers.MatrixApi.Client.RegisterTest do
def clear_cache(_context) do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
......@@ -4,7 +4,7 @@ defmodule PlasmaWeb.Controllers.MatrixApi.Client.R0.RoomsTest do
setup %{conn: conn} do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
response =
conn
......
......@@ -30,7 +30,7 @@ defmodule PlasmaWeb.Controllers.MatrixApi.Client.R0.UserControllerTest do
setup %{conn: conn} do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
response =
conn
......
......@@ -5,7 +5,7 @@ defmodule PlasmaWeb.Plugs.InteractiveAuthFlowTest do
def clear_cache(_context) do
PlasmaHS.Plugs.AuthSessionCache.flush()
PlasmaRepo.Users.AccessTokenCache.flush()
PlasmaRepo.Channels.EventTypeCache.flush()
PlasmaRepo.Events.EventTypeCache.flush()
:ok
end
......
......@@ -2,11 +2,11 @@ defmodule PlasmaRepo.Factory do
use ExMachina.Ecto, repo: PlasmaRepo.Repo
def event_type_factory() do
%PlasmaRepo.Channels.EventType{name: "event.type.test"}
%PlasmaRepo.Events.EventType{name: "event.type.test"}
end
def event_factory() do
%PlasmaRepo.Channels.Event{
%PlasmaRepo.Events.Event{
event_id: sequence("event"),
sequence_number: 1,
state_key: sequence("state"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment