mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-22 08:01:00 +00:00
Merge pull request #7 from chrismccord/fix/avoid_raise_error_on_duplicated_song
Handle unique song title constraint error on upload
This commit is contained in:
commit
632b211c44
2 changed files with 5 additions and 1 deletions
|
@ -196,7 +196,7 @@ defmodule LiveBeats.MediaLibrary do
|
||||||
{:error, failed_op, failed_val, _changes} ->
|
{:error, failed_op, failed_val, _changes} ->
|
||||||
failed_op =
|
failed_op =
|
||||||
case failed_op do
|
case failed_op do
|
||||||
{:song, _number} -> :invalid_song
|
{:song, _number} -> "Invalid song (#{failed_val.changes.title})"
|
||||||
:is_songs_count_updated? -> :invalid
|
:is_songs_count_updated? -> :invalid
|
||||||
failed_op -> failed_op
|
failed_op -> failed_op
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,10 @@ defmodule LiveBeats.MediaLibrary.Song do
|
||||||
song
|
song
|
||||||
|> cast(attrs, [:album_artist, :artist, :title, :attribution, :date_recorded, :date_released])
|
|> cast(attrs, [:album_artist, :artist, :title, :attribution, :date_recorded, :date_released])
|
||||||
|> validate_required([:artist, :title])
|
|> validate_required([:artist, :title])
|
||||||
|
|> unique_constraint(:title,
|
||||||
|
message: "is a duplicated from another song",
|
||||||
|
name: "songs_user_id_title_artist_index"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def put_user(%Ecto.Changeset{} = changeset, %Accounts.User{} = user) do
|
def put_user(%Ecto.Changeset{} = changeset, %Accounts.User{} = user) do
|
||||||
|
|
Loading…
Reference in a new issue