Add LastFm.Feed.all_artists/0 and LastFm.Feed.all_albums/0
This commit is contained in:
@@ -37,6 +37,32 @@ defmodule LastFm.Feed do
|
|||||||
:ets.select_reverse(__MODULE__, m)
|
:ets.select_reverse(__MODULE__, m)
|
||||||
end
|
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
|
@spec subscribe() :: :ok
|
||||||
def subscribe do
|
def subscribe do
|
||||||
Phoenix.PubSub.subscribe(LastFm.PubSub, "feed:update")
|
Phoenix.PubSub.subscribe(LastFm.PubSub, "feed:update")
|
||||||
|
|||||||
@@ -46,5 +46,15 @@ defmodule LastFm.FeedTest do
|
|||||||
:ok = Feed.update([@track_two, @track_one])
|
:ok = Feed.update([@track_two, @track_one])
|
||||||
assert [@track_two, @track_one] == Feed.all_tracks()
|
assert [@track_two, @track_one] == Feed.all_tracks()
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user