Add LastFm.Feed.all_artists/0 and LastFm.Feed.all_albums/0

This commit is contained in:
Claudio Ortolina
2024-12-10 14:57:28 +03:00
parent a6e1e4e34a
commit c2ccb7dde2
2 changed files with 36 additions and 0 deletions
+26
View File
@@ -37,6 +37,32 @@ defmodule LastFm.Feed do
:ets.select_reverse(__MODULE__, m)
end
@spec all_artists() :: [LastFm.Artist.t()]
def all_artists do
m = [
{
{:"$1", %{artist: :"$2"}},
[],
[:"$2"]
}
]
:ets.select_reverse(__MODULE__, m) |> Enum.uniq()
end
@spec all_albums() :: [LastFm.Album.t()]
def all_albums do
m = [
{
{:"$1", %{album: :"$2"}},
[],
[:"$2"]
}
]
:ets.select_reverse(__MODULE__, m) |> Enum.uniq()
end
@spec subscribe() :: :ok
def subscribe do
Phoenix.PubSub.subscribe(LastFm.PubSub, "feed:update")
+10
View File
@@ -46,5 +46,15 @@ defmodule LastFm.FeedTest do
:ok = Feed.update([@track_two, @track_one])
assert [@track_two, @track_one] == Feed.all_tracks()
end
test "it returns artists in descending order of scrobble" do
:ok = Feed.update([@track_two, @track_one])
assert [@track_one.artist] == Feed.all_artists()
end
test "it returns albums in descending order of scrobble" do
:ok = Feed.update([@track_two, @track_one])
assert [@track_one.album] == Feed.all_albums()
end
end
end