Store artists when importing a record

This commit is contained in:
Claudio Ortolina
2024-09-24 09:40:52 +01:00
parent 089e61a574
commit bcb70c9e1b
3 changed files with 28 additions and 1 deletions
+8
View File
@@ -27,9 +27,17 @@ defmodule MusicLibrary.Records.Record do
def changeset(record, attrs) do
record
|> cast(attrs, [:type, :title, :musicbrainz_id, :year, :genres, :image_url, :image_data])
|> cast_embed(:artists, with: &artist_changeset/2)
|> validate_required([:type, :title, :musicbrainz_id, :year, :genres])
end
@doc false
def artist_changeset(artist, attrs) do
artist
|> cast(attrs, [:name, :sort_name, :disambiguation, :musicbrainz_id])
|> validate_required([:name, :sort_name, :musicbrainz_id])
end
def add_artists(record, artists_attrs) do
record
|> change()
@@ -106,6 +106,8 @@ defmodule MusicLibraryWeb.RecordLive.SearchComponent do
end
end
defp parse_year(nil), do: ""
defp parse_year(iso_date) do
case Date.from_iso8601(iso_date) do
{:ok, date} -> date.year