mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
context: duplicate_reports
This commit is contained in:
parent
1044f9a9f8
commit
ff6553e875
4 changed files with 192 additions and 0 deletions
|
@ -32,6 +32,9 @@ config :philomena, PhilomenaWeb.Endpoint,
|
|||
render_errors: [view: PhilomenaWeb.ErrorView, accepts: ~w(html json)],
|
||||
pubsub: [name: Philomena.PubSub, adapter: Phoenix.PubSub.PG2]
|
||||
|
||||
config :philomena, :generators,
|
||||
migration: false
|
||||
|
||||
config :phoenix, :template_engines,
|
||||
slim: PhoenixSlime.Engine,
|
||||
slime: PhoenixSlime.Engine,
|
||||
|
|
104
lib/philomena/duplicate_reports.ex
Normal file
104
lib/philomena/duplicate_reports.ex
Normal file
|
@ -0,0 +1,104 @@
|
|||
defmodule Philomena.DuplicateReports do
|
||||
@moduledoc """
|
||||
The DuplicateReports context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Philomena.Repo
|
||||
|
||||
alias Philomena.DuplicateReports.DuplicateReport
|
||||
|
||||
@doc """
|
||||
Returns the list of duplicate_reports.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_duplicate_reports()
|
||||
[%DuplicateReport{}, ...]
|
||||
|
||||
"""
|
||||
def list_duplicate_reports do
|
||||
Repo.all(DuplicateReport)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single duplicate_report.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Duplicate report does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_duplicate_report!(123)
|
||||
%DuplicateReport{}
|
||||
|
||||
iex> get_duplicate_report!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_duplicate_report!(id), do: Repo.get!(DuplicateReport, id)
|
||||
|
||||
@doc """
|
||||
Creates a duplicate_report.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_duplicate_report(%{field: value})
|
||||
{:ok, %DuplicateReport{}}
|
||||
|
||||
iex> create_duplicate_report(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_duplicate_report(attrs \\ %{}) do
|
||||
%DuplicateReport{}
|
||||
|> DuplicateReport.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a duplicate_report.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_duplicate_report(duplicate_report, %{field: new_value})
|
||||
{:ok, %DuplicateReport{}}
|
||||
|
||||
iex> update_duplicate_report(duplicate_report, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_duplicate_report(%DuplicateReport{} = duplicate_report, attrs) do
|
||||
duplicate_report
|
||||
|> DuplicateReport.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a DuplicateReport.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_duplicate_report(duplicate_report)
|
||||
{:ok, %DuplicateReport{}}
|
||||
|
||||
iex> delete_duplicate_report(duplicate_report)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_duplicate_report(%DuplicateReport{} = duplicate_report) do
|
||||
Repo.delete(duplicate_report)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking duplicate_report changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_duplicate_report(duplicate_report)
|
||||
%Ecto.Changeset{source: %DuplicateReport{}}
|
||||
|
||||
"""
|
||||
def change_duplicate_report(%DuplicateReport{} = duplicate_report) do
|
||||
DuplicateReport.changeset(duplicate_report, %{})
|
||||
end
|
||||
end
|
23
lib/philomena/duplicate_reports/duplicate_report.ex
Normal file
23
lib/philomena/duplicate_reports/duplicate_report.ex
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule Philomena.DuplicateReports.DuplicateReport do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "duplicate_reports" do
|
||||
belongs_to :image, Philomena.Images.Image
|
||||
belongs_to :duplicate_of_image, Philomena.Images.Image
|
||||
belongs_to :user, Philomena.Users.User
|
||||
belongs_to :modifier, Philomena.Users.User
|
||||
|
||||
field :reason, :string
|
||||
field :state, :string, default: "open"
|
||||
|
||||
timestamps(inserted_at: :created_at)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(duplicate_report, attrs) do
|
||||
duplicate_report
|
||||
|> cast(attrs, [])
|
||||
|> validate_required([])
|
||||
end
|
||||
end
|
62
test/philomena/duplicate_reports_test.exs
Normal file
62
test/philomena/duplicate_reports_test.exs
Normal file
|
@ -0,0 +1,62 @@
|
|||
defmodule Philomena.DuplicateReportsTest do
|
||||
use Philomena.DataCase
|
||||
|
||||
alias Philomena.DuplicateReports
|
||||
|
||||
describe "duplicate_reports" do
|
||||
alias Philomena.DuplicateReports.DuplicateReport
|
||||
|
||||
@valid_attrs %{}
|
||||
@update_attrs %{}
|
||||
@invalid_attrs %{}
|
||||
|
||||
def duplicate_report_fixture(attrs \\ %{}) do
|
||||
{:ok, duplicate_report} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> DuplicateReports.create_duplicate_report()
|
||||
|
||||
duplicate_report
|
||||
end
|
||||
|
||||
test "list_duplicate_reports/0 returns all duplicate_reports" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert DuplicateReports.list_duplicate_reports() == [duplicate_report]
|
||||
end
|
||||
|
||||
test "get_duplicate_report!/1 returns the duplicate_report with given id" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert DuplicateReports.get_duplicate_report!(duplicate_report.id) == duplicate_report
|
||||
end
|
||||
|
||||
test "create_duplicate_report/1 with valid data creates a duplicate_report" do
|
||||
assert {:ok, %DuplicateReport{} = duplicate_report} = DuplicateReports.create_duplicate_report(@valid_attrs)
|
||||
end
|
||||
|
||||
test "create_duplicate_report/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = DuplicateReports.create_duplicate_report(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_duplicate_report/2 with valid data updates the duplicate_report" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert {:ok, %DuplicateReport{} = duplicate_report} = DuplicateReports.update_duplicate_report(duplicate_report, @update_attrs)
|
||||
end
|
||||
|
||||
test "update_duplicate_report/2 with invalid data returns error changeset" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = DuplicateReports.update_duplicate_report(duplicate_report, @invalid_attrs)
|
||||
assert duplicate_report == DuplicateReports.get_duplicate_report!(duplicate_report.id)
|
||||
end
|
||||
|
||||
test "delete_duplicate_report/1 deletes the duplicate_report" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert {:ok, %DuplicateReport{}} = DuplicateReports.delete_duplicate_report(duplicate_report)
|
||||
assert_raise Ecto.NoResultsError, fn -> DuplicateReports.get_duplicate_report!(duplicate_report.id) end
|
||||
end
|
||||
|
||||
test "change_duplicate_report/1 returns a duplicate_report changeset" do
|
||||
duplicate_report = duplicate_report_fixture()
|
||||
assert %Ecto.Changeset{} = DuplicateReports.change_duplicate_report(duplicate_report)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue