From 9e35238cab4bc0f8ac91b43f25bc06a3dbe7049d Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 14 Nov 2024 21:53:29 -0500 Subject: [PATCH] Fix single-source saving bug --- .../controllers/image/source_controller.ex | 10 +++++++++- lib/philomena_web/controllers/image_controller.ex | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/philomena_web/controllers/image/source_controller.ex b/lib/philomena_web/controllers/image/source_controller.ex index 373dcc10..2dbc4f47 100644 --- a/lib/philomena_web/controllers/image/source_controller.ex +++ b/lib/philomena_web/controllers/image/source_controller.ex @@ -4,6 +4,7 @@ defmodule PhilomenaWeb.Image.SourceController do alias Philomena.SourceChanges.SourceChange alias Philomena.UserStatistics alias Philomena.Images.Image + alias Philomena.Images.Source alias Philomena.Images alias Philomena.Repo import Ecto.Query @@ -41,7 +42,9 @@ defmodule PhilomenaWeb.Image.SourceController do PhilomenaWeb.Api.Json.ImageView.render("show.json", %{image: image, interactions: []}) ) - changeset = Images.change_image(image) + changeset = + %{image | sources: sources_for_edit(image.sources)} + |> Images.change_image() source_change_count = SourceChange @@ -74,4 +77,9 @@ defmodule PhilomenaWeb.Image.SourceController do ) end end + + # TODO: this is duplicated in ImageController + defp sources_for_edit(), do: [%Source{}] + defp sources_for_edit([]), do: sources_for_edit() + defp sources_for_edit(sources), do: sources end diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 990fcfd3..4088fe56 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -219,6 +219,7 @@ defmodule PhilomenaWeb.ImageController do end end + # TODO: this is duplicated in Image.SourceController defp sources_for_edit(), do: [%Source{}] defp sources_for_edit([]), do: sources_for_edit() defp sources_for_edit(sources), do: sources