Skip to content

Commit

Permalink
cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 30, 2024
1 parent 5ee92e7 commit 9e59574
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 29 deletions.
21 changes: 12 additions & 9 deletions lib/banchan/offerings/offerings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/banchan/uploads/upload_delete_listener.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/banchan/uploads/uploads.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ defmodule Banchan.Uploads do
end
end

def prune_uploads() do
def prune_uploads do
{:ok, {count, _}} =
Repo.transaction(fn ->
columns =
Expand Down
1 change: 1 addition & 0 deletions lib/banchan_web/live/discover_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
2 changes: 1 addition & 1 deletion lib/banchan_web/live/work_live/work.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +26,7 @@ defmodule BanchanWeb.WorkLive.Work do
alias Surface.Components.Form.{ErrorTag, Field}

alias BanchanWeb.Components.{
Button,
Collapse,
Icon,
Layout,
Expand Down
9 changes: 3 additions & 6 deletions test/banchan/commissions/commissions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ defmodule Banchan.CommissionsTest do
offering,
%{
slots: 1
},
nil
}
)

{:ok, comm1} = new_comm.()
Expand All @@ -134,8 +133,7 @@ defmodule Banchan.CommissionsTest do
offering,
%{
slots: 2
},
nil
}
)

{:ok, _comm2} = Commissions.update_status(user, comm2, :accepted)
Expand All @@ -152,8 +150,7 @@ defmodule Banchan.CommissionsTest do
Offerings.update_offering(
user,
offering |> Repo.reload(),
%{open: true},
nil
%{open: true}
)

{:ok, comm3} = new_comm.()
Expand Down
10 changes: 4 additions & 6 deletions test/banchan/offerings_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
9 changes: 6 additions & 3 deletions test/banchan/works_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)"]
Expand Down
3 changes: 1 addition & 2 deletions test/support/fixtures/offerings_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ defmodule Banchan.OfferingsFixtures do
open: true
},
attrs
),
nil
)
)

offering
Expand Down
2 changes: 1 addition & 1 deletion test/support/fixtures/works_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit 9e59574

Please sign in to comment.