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

40 lines
841 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
@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-07 02:38:13 +02:00
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
def changeset(note, attrs) do
note
|> cast(attrs, @attrs)
2019-09-07 02:38:13 +02:00
|> validate_required(@required_attrs)
end
end