Prevent importing the same record twice
This commit is contained in:
@@ -48,6 +48,7 @@ defmodule MusicLibrary.Records.Record do
|
||||
|> cast_embed(:artists, with: &artist_changeset/2)
|
||||
|> generate_cover_hash()
|
||||
|> validate_required([:type, :title, :musicbrainz_id, :release, :genres])
|
||||
|> unique_constraint(:musicbrainz_id, name: "records_musicbrainz_id_format_index")
|
||||
end
|
||||
|
||||
@doc false
|
||||
|
||||
@@ -107,7 +107,13 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
|
||||
|> push_navigate(to: ~p"/wishlist/#{record.id}")}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, form: to_form(changeset))}
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(
|
||||
:error,
|
||||
gettext("Error importing record") <> "," <> inspect(changeset.errors)
|
||||
)
|
||||
|> push_patch(to: ~p"/wishlist")}
|
||||
|
||||
{:error, reason} ->
|
||||
{:noreply,
|
||||
|
||||
Reference in New Issue
Block a user