2019-07-23 13:49:22 +02:00
|
|
|
defmodule Mobilizon.Reports.Note do
|
|
|
|
@moduledoc """
|
2019-09-07 02:38:13 +02:00
|
|
|
Represents a note entity.
|
2019-07-23 13:49:22 +02:00
|
|
|
"""
|
2019-09-07 02:38:13 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
use Ecto.Schema
|
2019-09-07 02:38:13 +02:00
|
|
|
|
|
|
|
import Ecto.Changeset, only: [cast: 3, validate_required: 2]
|
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
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
|
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
@timestamps_opts [type: :utc_datetime]
|
2019-09-21 23:59:07 +02:00
|
|
|
|
2019-09-07 02:38:13 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
content: String.t(),
|
|
|
|
report: Report.t(),
|
|
|
|
moderator: Actor.t()
|
|
|
|
}
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
@derive {Jason.Encoder, only: [:content]}
|
|
|
|
schema "report_notes" do
|
|
|
|
field(:content, :string)
|
2019-09-07 02:38:13 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
belongs_to(:report, Report)
|
2019-09-07 02:38:13 +02:00
|
|
|
belongs_to(:moderator, Actor)
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2019-09-13 01:55:45 +02:00
|
|
|
def changeset(%__MODULE__{} = note, attrs) do
|
2019-07-23 13:49:22 +02:00
|
|
|
note
|
|
|
|
|> cast(attrs, @attrs)
|
2019-09-07 02:38:13 +02:00
|
|
|
|> validate_required(@required_attrs)
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
|
|
|
end
|