Files
music_library/lib/music_brainz/release_group_search_result.ex
T
Claudio Ortolina 7cf9b4e7f8 First pass at uniformed types, specs and docs
- spec public functions (skipping controllers, views, live views and
components)
- use types instead of explanations in docs
- remove redundant docs
- fix typos
2026-03-06 08:33:11 +00:00

31 lines
921 B
Elixir

defmodule MusicBrainz.ReleaseGroupSearchResult do
alias MusicBrainz.ReleaseGroup
@enforce_keys [:id, :type, :title, :artists, :release_date]
defstruct [:id, :type, :title, :artists, :release_date]
@type t :: %__MODULE__{
id: String.t(),
type: :album | :ep | :live | :compilation | :single | :other,
title: String.t(),
artists: String.t(),
release_date: String.t() | nil
}
@spec from_api_response(map()) :: t()
def from_api_response(rg) do
%__MODULE__{
id: rg["id"],
type: ReleaseGroup.parse_type(rg["primary-type"]),
title: rg["title"],
artists: Enum.map_join(rg["artist-credit"], ", ", fn ac -> ac["artist"]["name"] end),
release_date: rg["first-release-date"]
}
end
@spec thumb_url(t()) :: String.t()
def thumb_url(rgr) do
"https://coverartarchive.org/release-group/#{rgr.id}/front-250"
end
end