Add record format (defaulting to CD)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,7 +24,12 @@
|
||||
row_click={fn {_id, record} -> JS.navigate(~p"/records/#{record}") end}
|
||||
>
|
||||
<:col :let={{_id, record}} label="Image">
|
||||
<img class="max-w-16 rounded-lg shadow" src={~p"/images/#{record.id}"} alt={record.title} />
|
||||
<span class="relative inline-block">
|
||||
<img class="max-w-16 rounded-lg shadow" src={~p"/images/#{record.id}"} alt={record.title} />
|
||||
<span class="absolute right-0 bottom-0 block h-6 w-6 text-white drop-shadow-md">
|
||||
<%= Records.Record.format_short_label(record.format) %>
|
||||
</span>
|
||||
</span>
|
||||
</:col>
|
||||
<:col :let={{_id, record}} label="Record">
|
||||
<p class="text-sm max-sm:text-xs"><%= Enum.map(record.artists, fn a -> a.name end) %></p>
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
</.header>
|
||||
|
||||
<div class="columns-2">
|
||||
<img class="w-full" src={~p"/images/#{@record.id}"} alt={@record.title} />
|
||||
<span class="relative inline-block">
|
||||
<img class="w-full shadow" src={~p"/images/#{@record.id}"} alt={@record.title} />
|
||||
<span class="absolute right-2 bottom-1 block h-6 w-6 text-white drop-shadow-md">
|
||||
<%= Records.Record.format_short_label(@record.format) %>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<.list>
|
||||
<:item title="Type"><%= @record.type %></:item>
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user