architex/lib/architex_web/api_schemas/client/request/login.ex

38 lines
989 B
Elixir
Raw Normal View History

2021-09-01 12:43:55 +00:00
defmodule ArchitexWeb.Client.Request.Login do
use ArchitexWeb.APIRequest
2021-06-27 15:28:28 +00:00
# TODO: Identifier
@type t :: %__MODULE__{
type: String.t(),
password: String.t(),
device_id: String.t(),
initial_device_display_name: String.t()
}
2021-06-27 15:28:28 +00:00
@primary_key false
embedded_schema do
field :type, :string
field :password, :string
field :device_id, :string
field :initial_device_display_name, :string
2021-07-13 15:08:07 +00:00
embeds_one :identifier, Identifier, primary_key: false do
field :type, :string
field :user, :string
end
2021-06-27 15:28:28 +00:00
end
def changeset(data, params) do
data
2021-07-10 21:16:00 +00:00
|> cast(params, [:type, :password, :device_id, :initial_device_display_name])
2021-07-13 15:08:07 +00:00
|> cast_embed(:identifier, with: &identifier_changeset/2, required: true)
2021-06-27 15:28:28 +00:00
|> validate_required([:type, :password])
end
2021-07-13 15:08:07 +00:00
def identifier_changeset(identifier, params) do
identifier
|> cast(params, [:type, :user])
|> validate_required([:type, :user])
end
2021-06-27 15:28:28 +00:00
end