debianize-mobilizon/lib/mobilizon/media/file.ex

38 lines
799 B
Elixir
Raw Normal View History

defmodule Mobilizon.Media.File do
@moduledoc """
2019-09-07 02:36:37 +02:00
Represents a file entity.
"""
2019-09-07 02:36:37 +02:00
use Ecto.Schema
2019-09-07 02:36:37 +02:00
import Ecto.Changeset, only: [cast: 3, validate_required: 2]
@type t :: %__MODULE__{
name: String.t(),
url: String.t(),
content_type: String.t(),
size: integer
}
@required_attrs [:name, :url]
@optional_attrs [:content_type, :size]
@attrs @required_attrs ++ @optional_attrs
embedded_schema do
field(:name, :string)
field(:url, :string)
field(:content_type, :string)
field(:size, :integer)
timestamps()
end
@doc false
2019-09-07 02:36:37 +02:00
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
def changeset(file, attrs) do
file
|> cast(attrs, @attrs)
|> validate_required(@required_attrs)
end
end