Extract authorization functions from state resolution

Add function to get room server's pid
This commit is contained in:
Pim Kunis 2021-07-28 17:23:48 +02:00
parent ee4c41ce77
commit 65368dc2d4
5 changed files with 391 additions and 349 deletions

View file

@ -4,6 +4,7 @@ defmodule MatrixServerWeb.RoomController do
import MatrixServerWeb.Plug.Error
import Ecto.Changeset
alias MatrixServer.{Repo, Room, RoomServer}
alias MatrixServerWeb.API.{CreateRoom}
alias Ecto.Changeset
alias Plug.Conn
@ -11,9 +12,12 @@ defmodule MatrixServerWeb.RoomController do
def create(%Conn{assigns: %{account: account}} = conn, params) do
case CreateRoom.changeset(params) do
%Changeset{valid?: true} = cs ->
cs
|> apply_changes()
|> MatrixServer.RoomServer.create_room(account)
input = apply_changes(cs)
# TODO: refactor
%Room{id: room_id} = Repo.insert!(Room.create_changeset(input))
{:ok, pid} = RoomServer.get_room_server(room_id)
RoomServer.create_room(pid, account, input)
conn
|> put_status(200)