2019-05-22 14:12:11 +02:00
|
|
|
defmodule Mobilizon.Media.Picture do
|
|
|
|
@moduledoc """
|
2019-09-07 02:36:37 +02:00
|
|
|
Represents a picture 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, cast_embed: 2]
|
|
|
|
|
2019-05-31 17:58:03 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-07 02:36:37 +02:00
|
|
|
alias Mobilizon.Media.File
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{
|
|
|
|
file: File.t(),
|
|
|
|
actor: Actor.t()
|
|
|
|
}
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
schema "pictures" do
|
|
|
|
embeds_one(:file, File, on_replace: :update)
|
2019-05-31 17:58:03 +02:00
|
|
|
belongs_to(:actor, Actor)
|
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__{} = picture, attrs) do
|
2019-05-22 14:12:11 +02:00
|
|
|
picture
|
2019-05-31 17:58:03 +02:00
|
|
|
|> cast(attrs, [:actor_id])
|
2019-05-22 14:12:11 +02:00
|
|
|
|> cast_embed(:file)
|
|
|
|
end
|
|
|
|
end
|