A website inspired by Last.fm that will keep track of your listening statistics
lastfm music statistics
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove user filter from artist list by count. Add user-specific artist list method to user service

oscar345 beee691a 0f98580f

+59 -3
+5
internal/services/artist.go
··· 38 38 } 39 39 40 40 func (as *ArtistService) ListArtistByCount(ctx context.Context, filter filters.Count) ([]models.Artist, pagination.Page, error) { 41 + // Since this should return a general list, we do not want to filter on user. The user service 42 + // should be used to get the user specific list. 43 + filter.UserID = 0 44 + 41 45 counts, page, err := as.artistScrobbleRepo.ListCount(ctx, filter) 42 46 if err != nil { 43 47 return nil, page, err ··· 61 65 items := enum.Map(counts, func(item models.CountMBID) models.Artist { 62 66 artist := artists[item.MBID] 63 67 image := images[item.MBID] 68 + 64 69 return models.Artist{ 65 70 MBID: item.MBID, 66 71 Name: artist.Name,
+54 -3
internal/services/user.go
··· 1 1 package services 2 2 3 - import "github.com/oscar345/keeptrack/internal/repo" 3 + import ( 4 + "context" 5 + 6 + "github.com/oscar345/keeptrack/internal/filters" 7 + "github.com/oscar345/keeptrack/internal/models" 8 + "github.com/oscar345/keeptrack/internal/providers" 9 + "github.com/oscar345/keeptrack/internal/repo" 10 + "github.com/oscar345/keeptrack/pkg/enum" 11 + "github.com/oscar345/keeptrack/pkg/pagination" 12 + ) 4 13 5 14 type UserService struct { 6 - userRepo repo.UserRepo 7 - userFollowRepo repo.UserFollowRepo 15 + userRepo repo.UserRepo 16 + userFollowRepo repo.UserFollowRepo 17 + artistRepo repo.ArtistRepo 18 + artistScrobbleRepo repo.ArtistScrobbleRepo 19 + mediaProvider *providers.MediaProvider 8 20 } 9 21 10 22 func NewUserService(userRepo repo.UserRepo, userFollowRepo repo.UserFollowRepo) *UserService { ··· 13 25 userFollowRepo: userFollowRepo, 14 26 } 15 27 } 28 + 29 + func (us *UserService) ListArtistsByCount( 30 + ctx context.Context, userID int, filter filters.Count, 31 + ) ([]models.Artist, pagination.Page, error) { 32 + filter.UserID = userID 33 + counts, page, err := us.artistScrobbleRepo.ListCount(ctx, filter) 34 + if err != nil { 35 + return nil, page, err 36 + } 37 + 38 + mbids := enum.Map(counts, func(item models.CountMBID) string { 39 + return item.MBID 40 + }) 41 + 42 + artists, err := us.artistRepo.ListByIDs(ctx, mbids) 43 + if err != nil { 44 + return nil, page, err 45 + } 46 + 47 + images, err := us.mediaProvider.ListArtistsImages(ctx, mbids) 48 + 49 + if err != nil { 50 + return nil, page, err 51 + } 52 + 53 + items := enum.Map(counts, func(item models.CountMBID) models.Artist { 54 + artist := artists[item.MBID] 55 + image := images[item.MBID] 56 + 57 + return models.Artist{ 58 + MBID: item.MBID, 59 + Name: artist.Name, 60 + Count: item.Count, 61 + ImageURL: image, 62 + } 63 + }) 64 + 65 + return items, page, nil 66 + }