Skip to content

Commit

Permalink
Fix single-source saving bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Nov 15, 2024
1 parent 1bd5e89 commit 9e35238
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/philomena_web/controllers/image/source_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/philomena_web/controllers/image_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e35238

Please sign in to comment.