diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex index 83cbbbe2..bd58097a 100644 --- a/lib/music_library/records/record.ex +++ b/lib/music_library/records/record.ex @@ -6,6 +6,7 @@ defmodule MusicLibrary.Records.Record do @foreign_key_type :binary_id schema "records" do field :type, Ecto.Enum, values: [:album, :ep, :live, :compilation, :single, :other] + field :format, Ecto.Enum, values: [:cd, :vinyl, :blu_ray, :dvd, :multi] field :title, :string field :image_url, :string field :image_data, :binary @@ -26,7 +27,16 @@ defmodule MusicLibrary.Records.Record do @doc false def changeset(record, attrs) do record - |> cast(attrs, [:type, :title, :musicbrainz_id, :year, :genres, :image_url, :image_data]) + |> cast(attrs, [ + :type, + :format, + :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 @@ -47,4 +57,10 @@ defmodule MusicLibrary.Records.Record do def add_image_data(record, image_data) do change(record, image_data: image_data) end + + def format_short_label(:cd), do: "CD" + def format_short_label(:vinyl), do: "V" + def format_short_label(:blu_ray), do: "BR" + def format_short_label(:dvd), do: "DVD" + def format_short_label(:multi), do: "MLT" end diff --git a/lib/music_library_web/live/record_live/index.html.heex b/lib/music_library_web/live/record_live/index.html.heex index abd3eae2..aa4bbdc0 100644 --- a/lib/music_library_web/live/record_live/index.html.heex +++ b/lib/music_library_web/live/record_live/index.html.heex @@ -24,7 +24,12 @@ row_click={fn {_id, record} -> JS.navigate(~p"/records/#{record}") end} > <:col :let={{_id, record}} label="Image"> - {record.title} + + {record.title} + + <%= Records.Record.format_short_label(record.format) %> + + <:col :let={{_id, record}} label="Record">

<%= Enum.map(record.artists, fn a -> a.name end) %>

diff --git a/lib/music_library_web/live/record_live/show.html.heex b/lib/music_library_web/live/record_live/show.html.heex index 8559528e..153e2f3c 100644 --- a/lib/music_library_web/live/record_live/show.html.heex +++ b/lib/music_library_web/live/record_live/show.html.heex @@ -12,7 +12,12 @@
- {@record.title} + + {@record.title} + + <%= Records.Record.format_short_label(@record.format) %> + + <.list> <:item title="Type"><%= @record.type %> diff --git a/priv/repo/migrations/20240928175157_add_format_to_records.exs b/priv/repo/migrations/20240928175157_add_format_to_records.exs new file mode 100644 index 00000000..81ea4c25 --- /dev/null +++ b/priv/repo/migrations/20240928175157_add_format_to_records.exs @@ -0,0 +1,9 @@ +defmodule MusicLibrary.Repo.Migrations.AddFormatToRecords do + use Ecto.Migration + + def change do + alter table(:records) do + add :format, :string, default: "cd" + end + end +end diff --git a/test/support/fixtures/records_fixtures.ex b/test/support/fixtures/records_fixtures.ex index 1389405f..25063f59 100644 --- a/test/support/fixtures/records_fixtures.ex +++ b/test/support/fixtures/records_fixtures.ex @@ -43,6 +43,7 @@ defmodule MusicLibrary.RecordsFixtures do musicbrainz_id: musicbrainz_id, title: Enum.random(@titles), type: :album, + format: :cd, year: Enum.random(1969..2024) }) |> MusicLibrary.Records.create_record()