Make dependency injection more consistent

This commit is contained in:
Deluan 2024-05-08 22:21:38 -04:00
parent a0290587b9
commit 677d9947f3
11 changed files with 54 additions and 63 deletions

View file

@ -25,7 +25,7 @@ var _ = Describe("Album Lists", func() {
BeforeEach(func() {
ds = &tests.MockDataStore{}
mockRepo = ds.Album(ctx).(*tests.MockAlbumRepo)
router = New(ds, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
router = New(ds, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
w = httptest.NewRecorder()
})

View file

@ -12,6 +12,7 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/core/playback"
"github.com/navidrome/navidrome/core/scrobbler"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@ -39,11 +40,13 @@ type Router struct {
broker events.Broker
scrobbler scrobbler.PlayTracker
share core.Share
playback playback.PlaybackServer
}
func New(ds model.DataStore, artwork artwork.Artwork, streamer core.MediaStreamer, archiver core.Archiver,
players core.Players, externalMetadata core.ExternalMetadata, scanner scanner.Scanner, broker events.Broker,
playlists core.Playlists, scrobbler scrobbler.PlayTracker, share core.Share) *Router {
playlists core.Playlists, scrobbler scrobbler.PlayTracker, share core.Share, playback playback.PlaybackServer,
) *Router {
r := &Router{
ds: ds,
artwork: artwork,
@ -56,6 +59,7 @@ func New(ds model.DataStore, artwork artwork.Artwork, streamer core.MediaStreame
broker: broker,
scrobbler: scrobbler,
share: share,
playback: playback,
}
r.Handler = r.routes()
return r

View file

@ -43,8 +43,7 @@ func (api *Router) JukeboxControl(r *http.Request) (*responses.Subsonic, error)
return nil, err
}
pbServer := playback.GetInstance()
pb, err := pbServer.GetDeviceForUser(user.UserName)
pb, err := api.playback.GetDeviceForUser(user.UserName)
if err != nil {
return nil, err
}

View file

@ -29,7 +29,7 @@ var _ = Describe("MediaAnnotationController", func() {
ds = &tests.MockDataStore{}
playTracker = &fakePlayTracker{}
eventBroker = &fakeEventBroker{}
router = New(ds, nil, nil, nil, nil, nil, nil, eventBroker, nil, playTracker, nil)
router = New(ds, nil, nil, nil, nil, nil, nil, eventBroker, nil, playTracker, nil, nil)
})
Describe("Scrobble", func() {

View file

@ -30,7 +30,7 @@ var _ = Describe("MediaRetrievalController", func() {
MockedMediaFile: mockRepo,
}
artwork = &fakeArtwork{}
router = New(ds, artwork, nil, nil, nil, nil, nil, nil, nil, nil, nil)
router = New(ds, artwork, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
w = httptest.NewRecorder()
})