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

32 lines
840 B
Elixir
Raw Normal View History

defmodule ArchitexWeb.Client.Request.Messages do
use ArchitexWeb.APIRequest
2021-09-06 14:17:45 +00:00
@type t :: %__MODULE__{
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
@primary_key false
embedded_schema do
field :from, :string
field :to, :string
field :dir, :string
field :limit, :integer, default: 10
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)
|> validate_format(:from, ~r/^[0-9]*$/)
|> validate_format(:to, ~r/^[0-9]+$/)
end
end