mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 23:50:59 +00:00
decrement songs_number when a song is deleted
This commit is contained in:
parent
74c720180e
commit
984c1c8523
1 changed files with 13 additions and 1 deletions
|
@ -333,7 +333,19 @@ defmodule LiveBeats.MediaLibrary do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
Repo.delete(song)
|
Ecto.Multi.new()
|
||||||
|
|> Ecto.Multi.delete(:delete, song)
|
||||||
|
|> Ecto.Multi.update(:update_songs_number, fn _ ->
|
||||||
|
user = Accounts.get_user!(song.user_id)
|
||||||
|
|
||||||
|
user_params = %{
|
||||||
|
songs_number: user.songs_number - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Accounts.User.songs_changeset(user, user_params)
|
||||||
|
end)
|
||||||
|
|> Repo.transaction()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_song(song_or_changeset, attrs \\ %{})
|
def change_song(song_or_changeset, attrs \\ %{})
|
||||||
|
|
Loading…
Reference in a new issue