diff --git a/lib/banchan/offerings/offerings.ex b/lib/banchan/offerings/offerings.ex index ae24f178..d65b19ef 100644 --- a/lib/banchan/offerings/offerings.ex +++ b/lib/banchan/offerings/offerings.ex @@ -92,17 +92,20 @@ defmodule Banchan.Offerings do changeset end - with {:ok, changed} <- changeset |> Repo.update(returning: true) do - if !open_before? && changed.open do - Notifications.offering_opened(changed) - end + changeset + |> Repo.update(returning: true) + |> case do + {:ok, changed} -> + if !open_before? && changed.open do + Notifications.offering_opened(changed) + end - if open_before? && !changed.open do - Notifications.offering_closed(changed) - end + if open_before? && !changed.open do + Notifications.offering_closed(changed) + end + + {:ok, changed} - {:ok, changed} - else {:error, error} -> Repo.rollback(error) end diff --git a/lib/banchan/uploads/upload_delete_listener.ex b/lib/banchan/uploads/upload_delete_listener.ex index ade2109e..9998a631 100644 --- a/lib/banchan/uploads/upload_delete_listener.ex +++ b/lib/banchan/uploads/upload_delete_listener.ex @@ -1,4 +1,8 @@ defmodule Banchan.Uploads.UploadDeleteListener do + @moduledoc """ + Listens for Postgres notifications that are fired whenever an Upload row is + deleted, and queues deletion of the corresponding data. + """ use GenServer alias Banchan.Repo diff --git a/lib/banchan/uploads/uploads.ex b/lib/banchan/uploads/uploads.ex index fd9b78fc..ec744364 100644 --- a/lib/banchan/uploads/uploads.ex +++ b/lib/banchan/uploads/uploads.ex @@ -160,7 +160,7 @@ defmodule Banchan.Uploads do end end - def prune_uploads() do + def prune_uploads do {:ok, {count, _}} = Repo.transaction(fn -> columns = diff --git a/lib/banchan_web/live/discover_live/index.ex b/lib/banchan_web/live/discover_live/index.ex index d5e04d8e..91b9d79d 100644 --- a/lib/banchan_web/live/discover_live/index.ex +++ b/lib/banchan_web/live/discover_live/index.ex @@ -71,6 +71,7 @@ defmodule BanchanWeb.DiscoverLive.Index do end @impl true + # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity def handle_event("submit", search, socket) do sort_by = search["sort_by"] && String.to_existing_atom(search["sort_by"]) diff --git a/lib/banchan_web/live/work_live/work.ex b/lib/banchan_web/live/work_live/work.ex index 661ddd63..4cfe8653 100644 --- a/lib/banchan_web/live/work_live/work.ex +++ b/lib/banchan_web/live/work_live/work.ex @@ -9,7 +9,6 @@ defmodule BanchanWeb.WorkLive.Work do import BanchanWeb.StudioLive.Helpers - alias BanchanWeb.Components.Button alias Banchan.Commissions alias Banchan.Offerings alias Banchan.Repo @@ -27,6 +26,7 @@ defmodule BanchanWeb.WorkLive.Work do alias Surface.Components.Form.{ErrorTag, Field} alias BanchanWeb.Components.{ + Button, Collapse, Icon, Layout, diff --git a/test/banchan/commissions/commissions_test.exs b/test/banchan/commissions/commissions_test.exs index 74995c78..fd5a94f9 100644 --- a/test/banchan/commissions/commissions_test.exs +++ b/test/banchan/commissions/commissions_test.exs @@ -117,8 +117,7 @@ defmodule Banchan.CommissionsTest do offering, %{ slots: 1 - }, - nil + } ) {:ok, comm1} = new_comm.() @@ -134,8 +133,7 @@ defmodule Banchan.CommissionsTest do offering, %{ slots: 2 - }, - nil + } ) {:ok, _comm2} = Commissions.update_status(user, comm2, :accepted) @@ -152,8 +150,7 @@ defmodule Banchan.CommissionsTest do Offerings.update_offering( user, offering |> Repo.reload(), - %{open: true}, - nil + %{open: true} ) {:ok, comm3} = new_comm.() diff --git a/test/banchan/offerings_test.exs b/test/banchan/offerings_test.exs index 9ae18ce3..3279f136 100644 --- a/test/banchan/offerings_test.exs +++ b/test/banchan/offerings_test.exs @@ -37,8 +37,8 @@ defmodule Banchan.OfferingsTest do Notifications.mark_all_as_read(client) Notifications.mark_all_as_read(artist) - Offerings.update_offering(artist, offering |> Repo.reload(), %{open: false}, nil) - Offerings.update_offering(artist, offering |> Repo.reload(), %{open: true}, nil) + Offerings.update_offering(artist, offering |> Repo.reload(), %{open: false}) + Offerings.update_offering(artist, offering |> Repo.reload(), %{open: true}) Notifications.wait_for_notifications() @@ -248,8 +248,7 @@ defmodule Banchan.OfferingsTest do Offerings.update_offering( artist, offering |> Repo.reload(), - %{open: true}, - nil + %{open: true} ) # Now we can make comms again! @@ -430,8 +429,7 @@ defmodule Banchan.OfferingsTest do Offerings.update_offering( artist, offering |> Repo.reload(), - %{open: true, max_proposals: 4}, - nil + %{open: true, max_proposals: 4} ) # Now we can start making comms again! diff --git a/test/banchan/works_test.exs b/test/banchan/works_test.exs index a3036217..05b8b9cc 100644 --- a/test/banchan/works_test.exs +++ b/test/banchan/works_test.exs @@ -244,7 +244,7 @@ defmodule Banchan.WorksTest do } assert {:ok, %Work{} = work} = - Works.new_work(artist, studio, valid_attrs, uploads, commission: comm) + Works.new_work(artist, studio, valid_attrs, uploads: uploads, commission: comm) assert work.private == true assert work.description == "some description" @@ -272,14 +272,17 @@ defmodule Banchan.WorksTest do ) ] - assert {:error, %Ecto.Changeset{}} = Works.new_work(artist, studio, @invalid_attrs, uploads) + assert {:error, %Ecto.Changeset{}} = + Works.new_work(artist, studio, @invalid_attrs, uploads: uploads) end test "requires non-empty uploads" do artist = user_fixture() studio = studio_fixture([artist]) uploads = [] - assert {:error, changeset} = Works.new_work(artist, studio, @invalid_attrs, uploads) + + assert {:error, changeset} = + Works.new_work(artist, studio, @invalid_attrs, uploads: uploads) assert %{ uploads: ["should have at least 1 item(s)"] diff --git a/test/support/fixtures/offerings_fixtures.ex b/test/support/fixtures/offerings_fixtures.ex index d8d6e7a9..bbeff966 100644 --- a/test/support/fixtures/offerings_fixtures.ex +++ b/test/support/fixtures/offerings_fixtures.ex @@ -27,8 +27,7 @@ defmodule Banchan.OfferingsFixtures do open: true }, attrs - ), - nil + ) ) offering diff --git a/test/support/fixtures/works_fixtures.ex b/test/support/fixtures/works_fixtures.ex index 33e72287..13e91931 100644 --- a/test/support/fixtures/works_fixtures.ex +++ b/test/support/fixtures/works_fixtures.ex @@ -47,7 +47,7 @@ defmodule Banchan.WorksFixtures do mature: false }) |> Map.new(fn {k, v} -> {to_string(k), v} end), - uploads, + uploads: uploads, commission: Map.get(attrs, :commission), offering: Map.get(attrs, :offering) )