2021-09-05 10:49:41 +00:00
|
|
|
defmodule ArchitexWeb.Client.Request.Messages do
|
2021-09-09 15:26:40 +00:00
|
|
|
use ArchitexWeb.APIRequest
|
2021-09-05 10:49:41 +00:00
|
|
|
|
2021-09-06 14:17:45 +00:00
|
|
|
@type t :: %__MODULE__{
|
2021-09-07 18:24:06 +00:00
|
|
|
from: String.t(),
|
|
|
|
to: String.t() | nil,
|
|
|
|
dir: String.t(),
|
|
|
|
limit: integer() | nil,
|
|
|
|
filter: String.t() | nil
|
|
|
|
}
|
2021-09-06 14:17:45 +00:00
|
|
|
|
2021-09-05 10:49:41 +00:00
|
|
|
@primary_key false
|
|
|
|
embedded_schema do
|
|
|
|
field :from, :string
|
|
|
|
field :to, :string
|
|
|
|
field :dir, :string
|
2021-09-07 18:24:06 +00:00
|
|
|
field :limit, :integer, default: 10
|
2021-09-05 10:49:41 +00:00
|
|
|
field :filter, :string
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(data, params) do
|
|
|
|
data
|
|
|
|
|> cast(params, [:from, :to, :dir, :limit, :filter], empty_values: [])
|
|
|
|
|> validate_required([:dir])
|
|
|
|
|> Architex.validate_not_nil([:from])
|
|
|
|
|> validate_inclusion(:dir, ["b", "f"])
|
|
|
|
|> validate_number(:limit, greater_than: 0)
|
2021-09-06 14:08:49 +00:00
|
|
|
|> validate_format(:from, ~r/^[0-9]*$/)
|
|
|
|
|> validate_format(:to, ~r/^[0-9]+$/)
|
2021-09-05 10:49:41 +00:00
|
|
|
end
|
|
|
|
end
|