mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41:00 +00:00
delete repeated code
This commit is contained in:
parent
2c709ffe2a
commit
bd4d57377b
2 changed files with 3 additions and 20 deletions
|
@ -337,28 +337,11 @@ defmodule LiveBeats.MediaLibrary do
|
|||
end
|
||||
|
||||
def delete_song(%Song{} = song) do
|
||||
case File.rm(song.mp3_filepath) do
|
||||
:ok ->
|
||||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
Logger.info(
|
||||
"unable to delete song #{song.id} at #{song.mp3_filepath}, got: #{inspect(reason)}"
|
||||
)
|
||||
end
|
||||
delete_song_file(song)
|
||||
|
||||
Ecto.Multi.new()
|
||||
|> Ecto.Multi.delete(:delete, song)
|
||||
|> Ecto.Multi.update_all(
|
||||
:update_songs_count,
|
||||
fn _ ->
|
||||
from(u in Accounts.User,
|
||||
where: u.id == ^song.user_id,
|
||||
update: [inc: [songs_count: -1]]
|
||||
)
|
||||
end,
|
||||
[]
|
||||
)
|
||||
|> update_user_songs_count(song.user_id, -1)
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, _} -> :ok
|
||||
|
|
|
@ -78,7 +78,7 @@ defmodule LiveBeats.MediaLibraryTest do
|
|||
%{creation_dates: creation_dates}
|
||||
end
|
||||
|
||||
test "deletes the song expired before the required interval", %{
|
||||
test "deletes the songs expired before the required interval", %{
|
||||
creation_dates: [one_month_ago, three_months_ago, four_months_ago]
|
||||
} do
|
||||
user = user_fixture()
|
||||
|
|
Loading…
Reference in a new issue