2021-09-01 12:43:55 +00:00
|
|
|
defmodule ArchitexWeb.Client.AliasesController do
|
|
|
|
use ArchitexWeb, :controller
|
2021-07-30 13:56:24 +00:00
|
|
|
|
2021-09-01 12:43:55 +00:00
|
|
|
import ArchitexWeb.Error
|
2021-07-30 13:56:24 +00:00
|
|
|
|
2021-09-01 12:43:55 +00:00
|
|
|
alias Architex.Alias
|
2021-07-30 13:56:24 +00:00
|
|
|
|
2021-08-24 23:27:03 +00:00
|
|
|
@doc """
|
|
|
|
Create a new mapping from room alias to room ID.
|
|
|
|
|
|
|
|
Action for PUT /_matrix/client/r0/directory/room/{roomAlias}.
|
|
|
|
"""
|
2021-07-30 13:56:24 +00:00
|
|
|
def create(conn, %{"alias" => alias, "room_id" => room_id}) do
|
|
|
|
case Alias.create(alias, room_id) do
|
|
|
|
{:ok, _} ->
|
|
|
|
conn
|
|
|
|
|> put_status(200)
|
|
|
|
|> json(%{})
|
|
|
|
|
|
|
|
{:error, cs} ->
|
|
|
|
put_error(conn, Alias.get_error(cs))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: create error view for this?
|
|
|
|
def create(conn, _), do: put_error(conn, :bad_json)
|
|
|
|
end
|