debianize-mobilizon/lib/mobilizon/reports/note.ex

42 lines
878 B
Elixir
Raw Normal View History

defmodule Mobilizon.Reports.Note do
@moduledoc """
2019-09-07 02:38:13 +02:00
Represents a note entity.
"""
2019-09-07 02:38:13 +02:00
use Ecto.Schema
2019-09-07 02:38:13 +02:00
import Ecto.Changeset, only: [cast: 3, validate_required: 2]
alias Mobilizon.Actors.Actor
alias Mobilizon.Reports.Report
2019-09-07 02:38:13 +02:00
@required_attrs [:content, :moderator_id, :report_id]
@attrs @required_attrs
@timestamps_opts [type: :utc_datetime]
2019-09-07 02:38:13 +02:00
@type t :: %__MODULE__{
content: String.t(),
report: Report.t(),
moderator: Actor.t()
}
@derive {Jason.Encoder, only: [:content]}
schema "report_notes" do
field(:content, :string)
2019-09-07 02:38:13 +02:00
belongs_to(:report, Report)
2019-09-07 02:38:13 +02:00
belongs_to(:moderator, Actor)
timestamps()
end
@doc false
2019-09-13 01:55:45 +02:00
@spec changeset(t, map) :: Ecto.Changeset.t()
def changeset(%__MODULE__{} = note, attrs) do
note
|> cast(attrs, @attrs)
2019-09-07 02:38:13 +02:00
|> validate_required(@required_attrs)
end
end