🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
refactor: add GetStarred to artists
Deluana260e65307b6
diff --git a/persistence/artist_repository.go b/persistence/artist_repository.goindex 516a1c616..f9e1d58e7 100644--- a/persistence/artist_repository.go+++ b/persistence/artist_repository.go@@ -76,8 +76,7 @@ func (r *artistRepository) GetAll(options ...model.QueryOptions) (model.Artists,// TODO Cache the index (recalculate when there are changes to the DB)func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) {- sq := Select("artist_id as id", "artist as name", "count(distinct album_id) as album_count").- From("media_file").GroupBy("artist_id").OrderBy("name")+ sq := r.selectArtist().OrderBy("name")var all model.Artists// TODO Paginateerr := r.queryAll(sq, &all)@@ -93,7 +92,7 @@ func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) {idx = &model.ArtistIndex{ID: ax}fullIdx[ax] = idx}- idx.Artists = append(idx.Artists, model.Artist(a))+ idx.Artists = append(idx.Artists, a)}var result model.ArtistIndexesfor _, idx := range fullIdx {@@ -158,7 +157,10 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id}func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Artists, error) {- return nil, nil // TODO+ sq := r.selectArtist(options...).Where("starred = true")+ var starred model.Artists+ err := r.queryAll(sq, &starred)+ return starred, err}func (r *artistRepository) PurgeEmpty() error {diff --git a/persistence/artist_repository_test.go b/persistence/artist_repository_test.goindex d11ea86f4..f7e272c94 100644--- a/persistence/artist_repository_test.go+++ b/persistence/artist_repository_test.go@@ -1,6 +1,8 @@package persistenceimport (+ "context"+"github.com/astaxie/beego/orm""github.com/deluan/navidrome/log""github.com/deluan/navidrome/model"@@ -12,7 +14,8 @@ var _ = Describe("ArtistRepository", func() {var repo model.ArtistRepositoryBeforeEach(func() {- repo = NewArtistRepository(log.NewContext(nil), orm.NewOrm())+ ctx := context.WithValue(log.NewContext(nil), "user", &model.User{ID: "userid"})+ repo = NewArtistRepository(ctx, orm.NewOrm())})Describe("Count", func() {@@ -36,6 +39,14 @@ var _ = Describe("ArtistRepository", func() {})})+ Describe("GetStarred", func() {+ It("returns all starred records", func() {+ Expect(repo.GetStarred(model.QueryOptions{})).To(Equal(model.Artists{+ artistBeatles,+ }))+ })+ })+Describe("GetIndex", func() {It("returns the index", func() {idx, err := repo.GetIndex()diff --git a/persistence/persistence_suite_test.go b/persistence/persistence_suite_test.goindex 05867968e..e8cbeb45f 100644--- a/persistence/persistence_suite_test.go+++ b/persistence/persistence_suite_test.go@@ -20,9 +20,9 @@ import (func TestPersistence(t *testing.T) {tests.Init(t, true)- //os.Remove("./test-123.db")- //conf.Server.DbPath = "./test-123.db"- conf.Server.DbPath = "file::memory:?cache=shared"+ os.Remove("./test-123.db")+ conf.Server.DbPath = "./test-123.db"+ //conf.Server.DbPath = "file::memory:?cache=shared"New()db.EnsureDB()log.SetLevel(log.LevelCritical)@@ -31,7 +31,7 @@ func TestPersistence(t *testing.T) {}var artistKraftwerk = model.Artist{ID: "2", Name: "Kraftwerk", AlbumCount: 1}-var artistBeatles = model.Artist{ID: "3", Name: "The Beatles", AlbumCount: 2}+var artistBeatles = model.Artist{ID: "3", Name: "The Beatles", AlbumCount: 2, Starred: true}var testArtists = model.Artists{artistKraftwerk,artistBeatles,@@ -57,9 +57,11 @@ var testSongs = model.MediaFiles{songAntenna,}-var annAlbumRadioactivity = model.Annotation{AnnID: "1", UserID: "userid", ItemType: model.AlbumItemType, ItemID: "3", Starred: true}-var annSongComeTogether = model.Annotation{AnnID: "2", UserID: "userid", ItemType: model.MediaItemType, ItemID: "2", Starred: true}+var annArtistBeatles = model.Annotation{AnnID: "3", UserID: "userid", ItemType: model.ArtistItemType, ItemID: artistBeatles.ID, Starred: true}+var annAlbumRadioactivity = model.Annotation{AnnID: "1", UserID: "userid", ItemType: model.AlbumItemType, ItemID: albumRadioactivity.ID, Starred: true}+var annSongComeTogether = model.Annotation{AnnID: "2", UserID: "userid", ItemType: model.MediaItemType, ItemID: songComeTogether.ID, Starred: true}var testAnnotations = []model.Annotation{+ annArtistBeatles,annAlbumRadioactivity,annSongComeTogether,}