Only show similar artists from collection
This commit is contained in:
@@ -2,7 +2,7 @@ defmodule MusicLibrary.Artists do
|
|||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
alias MusicLibrary.Repo
|
alias MusicLibrary.Repo
|
||||||
|
|
||||||
alias MusicLibrary.Records.ArtistRecord
|
alias MusicLibrary.Records.{ArtistRecord, Record}
|
||||||
|
|
||||||
def get_artist!(musicbrainz_id) do
|
def get_artist!(musicbrainz_id) do
|
||||||
q =
|
q =
|
||||||
@@ -17,11 +17,11 @@ defmodule MusicLibrary.Artists do
|
|||||||
def get_similar_artists(artist) do
|
def get_similar_artists(artist) do
|
||||||
case LastFm.get_similar_artists(artist.musicbrainz_id, artist.name) do
|
case LastFm.get_similar_artists(artist.musicbrainz_id, artist.name) do
|
||||||
{:ok, artists} ->
|
{:ok, artists} ->
|
||||||
all_artist_ids = get_all_artist_ids()
|
collected_artist_ids = get_collected_artist_ids()
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
Enum.filter(artists, fn a ->
|
Enum.filter(artists, fn a ->
|
||||||
MapSet.member?(all_artist_ids, a.musicbrainz_id)
|
MapSet.member?(collected_artist_ids, a.musicbrainz_id)
|
||||||
end)}
|
end)}
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
@@ -34,4 +34,16 @@ defmodule MusicLibrary.Artists do
|
|||||||
|
|
||||||
q |> Repo.all() |> MapSet.new()
|
q |> Repo.all() |> MapSet.new()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_collected_artist_ids do
|
||||||
|
q =
|
||||||
|
from ar in ArtistRecord,
|
||||||
|
join: r in Record,
|
||||||
|
on: r.id == ar.record_id,
|
||||||
|
where: not is_nil(r.purchased_at),
|
||||||
|
distinct: true,
|
||||||
|
select: ar.musicbrainz_id
|
||||||
|
|
||||||
|
q |> Repo.all() |> MapSet.new()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user