Use embedded schemas for LastFm track, artist and album

Preparation for persisting the scrobble activity to database
This commit is contained in:
Claudio Ortolina
2025-05-30 17:01:12 +01:00
parent 06511f89db
commit 46ffa375af
3 changed files with 32 additions and 25 deletions
+12 -2
View File
@@ -1,6 +1,5 @@
defmodule LastFm.Artist do
@enforce_keys [:musicbrainz_id, :name]
defstruct [:musicbrainz_id, :name, :summary, :bio, :image, :play_count, :on_tour, :base_url]
use Ecto.Schema
@type t :: %__MODULE__{
musicbrainz_id: String.t(),
@@ -13,6 +12,17 @@ defmodule LastFm.Artist do
base_url: String.t()
}
embedded_schema do
field :musicbrainz_id, :string
field :name, :string
field :summary, :string
field :bio, :string
field :image, :string
field :play_count, :integer, default: 0
field :on_tour, :boolean, default: false
field :base_url, :string
end
def from_api_response(api_response) do
%__MODULE__{
musicbrainz_id: api_response["mbid"],