architex/lib/matrix_server_web/controllers/room_controller.ex

27 lines
593 B
Elixir
Raw Normal View History

2021-07-10 21:16:00 +00:00
defmodule MatrixServerWeb.RoomController do
use MatrixServerWeb, :controller
import MatrixServerWeb.Plug.Error
import Ecto.Changeset
alias MatrixServerWeb.API.{CreateRoom}
alias Ecto.Changeset
2021-07-17 15:38:20 +00:00
alias Plug.Conn
2021-07-10 21:16:00 +00:00
2021-07-17 15:38:20 +00:00
def create(%Conn{assigns: %{account: account}} = conn, params) do
2021-07-10 21:16:00 +00:00
case CreateRoom.changeset(params) do
%Changeset{valid?: true} = cs ->
2021-07-17 15:38:20 +00:00
cs
|> apply_changes()
|> MatrixServer.RoomServer.create_room(account)
2021-07-10 21:16:00 +00:00
conn
|> put_status(200)
|> json(%{})
_ ->
put_error(conn, :bad_json)
end
end
end