2020-11-26 11:41:13 +01:00
|
|
|
defmodule Mobilizon.Medias.File do
|
2019-05-22 14:12:11 +02:00
|
|
|
@moduledoc """
|
2019-09-07 02:36:37 +02:00
|
|
|
Represents a file entity.
|
2019-05-22 14:12:11 +02:00
|
|
|
"""
|
2019-09-07 02:36:37 +02:00
|
|
|
|
2019-05-22 14:12:11 +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
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
@derive Jason.Encoder
|
2019-05-22 14:12:11 +02:00
|
|
|
embedded_schema do
|
|
|
|
field(:name, :string)
|
|
|
|
field(:url, :string)
|
|
|
|
field(:content_type, :string)
|
2019-06-03 17:13:47 +02:00
|
|
|
field(:size, :integer)
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2019-09-13 01:55:45 +02:00
|
|
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
|
|
|
def changeset(%__MODULE__{} = file, attrs) do
|
2019-09-07 02:36:37 +02:00
|
|
|
file
|
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
2019-05-22 14:12:11 +02:00
|
|
|
end
|
|
|
|
end
|