Restructure code base
This commit is contained in:
parent
1e53776a8d
commit
f50f08061c
23 changed files with 245 additions and 213 deletions
38
lib/matrix_server_web/request/create_room.ex
Normal file
38
lib/matrix_server_web/request/create_room.ex
Normal file
|
@ -0,0 +1,38 @@
|
|||
defmodule MatrixServerWeb.Request.CreateRoom do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Ecto.Changeset
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :visibility, :string
|
||||
field :room_alias_name, :string
|
||||
field :name, :string
|
||||
field :topic, :string
|
||||
field :invite, {:array, :string}
|
||||
field :room_version, :string
|
||||
field :preset, :string
|
||||
# TODO: unimplemented:
|
||||
# creation_content, initial_state, invite_3pid, initial_state,
|
||||
# is_direct, power_level_content_override
|
||||
end
|
||||
|
||||
def changeset(params) do
|
||||
%__MODULE__{}
|
||||
|> cast(params, [
|
||||
:visibility,
|
||||
:room_alias_name,
|
||||
:name,
|
||||
:topic,
|
||||
:invite,
|
||||
:room_version,
|
||||
:preset
|
||||
])
|
||||
|> validate_inclusion(:preset, ["private_chat", "public_chat", "trusted_private_chat"])
|
||||
end
|
||||
|
||||
def get_error(%Changeset{errors: [error | _]}), do: get_error(error)
|
||||
def get_error(_), do: :bad_json
|
||||
end
|
31
lib/matrix_server_web/request/login.ex
Normal file
31
lib/matrix_server_web/request/login.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
defmodule MatrixServerWeb.Request.Login do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :type, :string
|
||||
field :password, :string
|
||||
field :device_id, :string
|
||||
field :initial_device_display_name, :string
|
||||
|
||||
embeds_one :identifier, Identifier, primary_key: false do
|
||||
field :type, :string
|
||||
field :user, :string
|
||||
end
|
||||
end
|
||||
|
||||
def changeset(params) do
|
||||
%__MODULE__{}
|
||||
|> cast(params, [:type, :password, :device_id, :initial_device_display_name])
|
||||
|> cast_embed(:identifier, with: &identifier_changeset/2, required: true)
|
||||
|> validate_required([:type, :password])
|
||||
end
|
||||
|
||||
def identifier_changeset(identifier, params) do
|
||||
identifier
|
||||
|> cast(params, [:type, :user])
|
||||
|> validate_required([:type, :user])
|
||||
end
|
||||
end
|
33
lib/matrix_server_web/request/register.ex
Normal file
33
lib/matrix_server_web/request/register.ex
Normal file
|
@ -0,0 +1,33 @@
|
|||
defmodule MatrixServerWeb.Request.Register do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Ecto.Changeset
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :device_id, :string
|
||||
field :initial_device_display_name, :string
|
||||
field :password, :string
|
||||
field :username, :string
|
||||
field :inhibit_login, :boolean, default: false
|
||||
end
|
||||
|
||||
def changeset(params) do
|
||||
%__MODULE__{}
|
||||
|> cast(params, [
|
||||
:device_id,
|
||||
:initial_device_display_name,
|
||||
:password,
|
||||
:username,
|
||||
:inhibit_login
|
||||
])
|
||||
|> validate_required([:password])
|
||||
end
|
||||
|
||||
def get_error(%Changeset{errors: [error | _]}), do: get_error(error)
|
||||
def get_error({:localpart, {_, [{:constraint, :unique} | _]}}), do: :user_in_use
|
||||
def get_error({:localpart, {_, [{:validation, _} | _]}}), do: :invalid_username
|
||||
def get_error(_), do: :bad_json
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue