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
|
|
|
|
|
|
|
|
@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
|
2019-09-07 02:38:13 +02:00
|
|
|
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
2019-07-23 13:49:22 +02:00
|
|
|
def changeset(note, attrs) do
|
|
|
|
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
|