Removed dependency on engine from persistence
This commit is contained in:
+3
-3
@@ -20,13 +20,13 @@ type Browser interface {
|
||||
GetSong(id string) (*Entry, error)
|
||||
}
|
||||
|
||||
func NewBrowser(pr PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
|
||||
func NewBrowser(pr domain.PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
|
||||
ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain.MediaFileRepository) Browser {
|
||||
return &browser{pr, fr, ir, ar, alr, mr}
|
||||
}
|
||||
|
||||
type browser struct {
|
||||
propRepo PropertyRepository
|
||||
propRepo domain.PropertyRepository
|
||||
folderRepo domain.MediaFolderRepository
|
||||
indexRepo domain.ArtistIndexRepository
|
||||
artistRepo domain.ArtistRepository
|
||||
@@ -39,7 +39,7 @@ func (b *browser) MediaFolders() (domain.MediaFolders, error) {
|
||||
}
|
||||
|
||||
func (b *browser) Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error) {
|
||||
l, err := b.propRepo.DefaultGet(PropLastScan, "-1")
|
||||
l, err := b.propRepo.DefaultGet(domain.PropLastScan, "-1")
|
||||
ms, _ := strconv.ParseInt(l, 10, 64)
|
||||
lastModified := utils.ToTime(ms)
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ type ListGenerator interface {
|
||||
GetRandomSongs(size int) (Entries, error)
|
||||
}
|
||||
|
||||
func NewListGenerator(alr domain.AlbumRepository, mfr domain.MediaFileRepository, npr NowPlayingRepository) ListGenerator {
|
||||
func NewListGenerator(alr domain.AlbumRepository, mfr domain.MediaFileRepository, npr domain.NowPlayingRepository) ListGenerator {
|
||||
return &listGenerator{alr, mfr, npr}
|
||||
}
|
||||
|
||||
type listGenerator struct {
|
||||
albumRepo domain.AlbumRepository
|
||||
mfRepository domain.MediaFileRepository
|
||||
npRepo NowPlayingRepository
|
||||
npRepo domain.NowPlayingRepository
|
||||
}
|
||||
|
||||
func (g *listGenerator) query(qo domain.QueryOptions, offset int, size int) (Entries, error) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package engine
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
)
|
||||
|
||||
func CreateMockNowPlayingRepo() *MockNowPlaying {
|
||||
@@ -10,8 +12,8 @@ func CreateMockNowPlayingRepo() *MockNowPlaying {
|
||||
}
|
||||
|
||||
type MockNowPlaying struct {
|
||||
NowPlayingRepository
|
||||
data []NowPlayingInfo
|
||||
domain.NowPlayingRepository
|
||||
data []domain.NowPlayingInfo
|
||||
t time.Time
|
||||
err bool
|
||||
}
|
||||
@@ -20,12 +22,12 @@ func (m *MockNowPlaying) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Enqueue(info *NowPlayingInfo) error {
|
||||
func (m *MockNowPlaying) Enqueue(info *domain.NowPlayingInfo) error {
|
||||
if m.err {
|
||||
return errors.New("Error!")
|
||||
}
|
||||
|
||||
m.data = append(m.data, NowPlayingInfo{})
|
||||
m.data = append(m.data, domain.NowPlayingInfo{})
|
||||
copy(m.data[1:], m.data[0:])
|
||||
m.data[0] = *info
|
||||
|
||||
@@ -37,7 +39,7 @@ func (m *MockNowPlaying) Enqueue(info *NowPlayingInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Dequeue(playerId int) (*NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Dequeue(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -52,15 +54,15 @@ func (m *MockNowPlaying) Count(playerId int) (int64, error) {
|
||||
return int64(len(m.data)), nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) GetAll() ([]*NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) GetAll() ([]*domain.NowPlayingInfo, error) {
|
||||
np, err := m.Head(1)
|
||||
if np == nil || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*NowPlayingInfo{np}, err
|
||||
return []*domain.NowPlayingInfo{np}, err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Head(playerId int) (*NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Head(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -68,7 +70,7 @@ func (m *MockNowPlaying) Head(playerId int) (*NowPlayingInfo, error) {
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Tail(playerId int) (*NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Tail(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -77,7 +79,7 @@ func (m *MockNowPlaying) Tail(playerId int) (*NowPlayingInfo, error) {
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) ClearAll() {
|
||||
m.data = make([]NowPlayingInfo, 0)
|
||||
m.data = make([]domain.NowPlayingInfo, 0)
|
||||
m.err = false
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
)
|
||||
|
||||
func CreateMockPropertyRepo() *MockProperty {
|
||||
@@ -9,7 +11,7 @@ func CreateMockPropertyRepo() *MockProperty {
|
||||
}
|
||||
|
||||
type MockProperty struct {
|
||||
PropertyRepository
|
||||
domain.PropertyRepository
|
||||
data map[string]string
|
||||
err bool
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package engine
|
||||
|
||||
import "time"
|
||||
|
||||
const NowPlayingExpire = 60 * time.Minute
|
||||
|
||||
type NowPlayingInfo struct {
|
||||
TrackId string
|
||||
Start time.Time
|
||||
Username string
|
||||
PlayerId int
|
||||
PlayerName string
|
||||
}
|
||||
|
||||
// This repo must have the semantics of a FIFO queue, for each playerId
|
||||
type NowPlayingRepository interface {
|
||||
// Insert at the head of the queue
|
||||
Enqueue(*NowPlayingInfo) error
|
||||
|
||||
// Removes and returns the element at the end of the queue
|
||||
Dequeue(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Returns the element at the head of the queue (last inserted one)
|
||||
Head(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Returns the element at the end of the queue (first inserted one)
|
||||
Tail(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Size of the queue for the playerId
|
||||
Count(playerId int) (int64, error)
|
||||
|
||||
// Returns all tails from all playerIds
|
||||
GetAll() ([]*NowPlayingInfo, error)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package engine
|
||||
|
||||
const (
|
||||
PropLastScan = "LastScan"
|
||||
)
|
||||
|
||||
type Property struct {
|
||||
Id string
|
||||
Value string
|
||||
}
|
||||
|
||||
type PropertyRepository interface {
|
||||
Put(id string, value string) error
|
||||
Get(id string) (string, error)
|
||||
DefaultGet(id string, defaultValue string) (string, error)
|
||||
}
|
||||
+3
-3
@@ -21,14 +21,14 @@ type Scrobbler interface {
|
||||
NowPlaying(ctx context.Context, playerId int, playerName, trackId, username string) (*domain.MediaFile, error)
|
||||
}
|
||||
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository, npr NowPlayingRepository) Scrobbler {
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository, npr domain.NowPlayingRepository) Scrobbler {
|
||||
return &scrobbler{itunes, mr, npr}
|
||||
}
|
||||
|
||||
type scrobbler struct {
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
npRepo NowPlayingRepository
|
||||
npRepo domain.NowPlayingRepository
|
||||
}
|
||||
|
||||
func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId string) {
|
||||
@@ -96,6 +96,6 @@ func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, tr
|
||||
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
|
||||
}
|
||||
|
||||
info := &NowPlayingInfo{TrackId: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
||||
info := &domain.NowPlayingInfo{TrackId: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
||||
return mf, s.npRepo.Enqueue(info)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user