2019-12-03 14:54:07 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-12-03 14:54:07 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.ReportNote do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.ReportNote
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{}
|
|
|
|
|
|
|
|
schema "report_notes" do
|
|
|
|
field(:content, :string)
|
|
|
|
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
|
|
|
belongs_to(:activity, Activity, type: FlakeId.Ecto.CompatType)
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
2024-01-20 21:36:01 +00:00
|
|
|
@spec create(Ecto.UUID.t(), Ecto.UUID.t(), String.t()) ::
|
2019-12-03 14:54:07 +00:00
|
|
|
{:ok, ReportNote.t()} | {:error, Changeset.t()}
|
|
|
|
def create(user_id, activity_id, content) do
|
|
|
|
attrs = %{
|
|
|
|
user_id: user_id,
|
|
|
|
activity_id: activity_id,
|
|
|
|
content: content
|
|
|
|
}
|
|
|
|
|
|
|
|
%ReportNote{}
|
|
|
|
|> cast(attrs, [:user_id, :activity_id, :content])
|
|
|
|
|> validate_required([:user_id, :activity_id, :content])
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
2024-01-20 21:36:01 +00:00
|
|
|
@spec destroy(Ecto.UUID.t()) ::
|
2019-12-08 08:27:23 +00:00
|
|
|
{:ok, ReportNote.t()} | {:error, Changeset.t()}
|
|
|
|
def destroy(id) do
|
|
|
|
from(r in ReportNote, where: r.id == ^id)
|
|
|
|
|> Repo.one()
|
|
|
|
|> Repo.delete()
|
2019-12-03 14:54:07 +00:00
|
|
|
end
|
|
|
|
end
|