mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Introduced NowPlayingRepository. Don't do anything for now
This commit is contained in:
parent
b660a70688
commit
4748ce142f
7 changed files with 76 additions and 4 deletions
|
@ -23,7 +23,6 @@ func (c *MediaAnnotationController) Scrobble() {
|
|||
id := c.RequiredParamString("id", "Required id parameter is missing")
|
||||
time := c.ParamTime("time", time.Now())
|
||||
submission := c.ParamBool("submission", false)
|
||||
println(submission)
|
||||
if submission {
|
||||
mf, err := c.scrobbler.Register(id, time, true)
|
||||
if err != nil {
|
||||
|
|
|
@ -22,6 +22,7 @@ func init() {
|
|||
|
||||
// Engine (Use cases)
|
||||
utils.DefineSingleton(new(engine.PropertyRepository), persistence.NewPropertyRepository)
|
||||
utils.DefineSingleton(new(engine.NowPlayingRepository), persistence.NewNowPlayingRepository)
|
||||
utils.DefineSingleton(new(engine.Browser), engine.NewBrowser)
|
||||
utils.DefineSingleton(new(engine.ListGenerator), engine.NewListGenerator)
|
||||
utils.DefineSingleton(new(engine.Cover), engine.NewCover)
|
||||
|
|
28
engine/mock_nowplaying_repo.go
Normal file
28
engine/mock_nowplaying_repo.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateMockNowPlayingRepo() *MockNowPlaying {
|
||||
return &MockNowPlaying{data: make(map[string]time.Time)}
|
||||
}
|
||||
|
||||
type MockNowPlaying struct {
|
||||
NowPlayingRepository
|
||||
data map[string]time.Time
|
||||
err bool
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Add(id string) error {
|
||||
if m.err {
|
||||
return errors.New("Error!")
|
||||
}
|
||||
m.data[id] = time.Now()
|
||||
return nil
|
||||
}
|
14
engine/nowplaying.go
Normal file
14
engine/nowplaying.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package engine
|
||||
|
||||
import "time"
|
||||
|
||||
const NowPlayingExpire = time.Duration(30) * time.Minute
|
||||
|
||||
type NowPlayingInfo struct {
|
||||
TrackId string
|
||||
Start time.Time
|
||||
}
|
||||
|
||||
type NowPlayingRepository interface {
|
||||
Add(trackId string) error
|
||||
}
|
|
@ -13,13 +13,14 @@ type Scrobbler interface {
|
|||
Register(id string, playDate time.Time, submit bool) (*domain.MediaFile, error)
|
||||
}
|
||||
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository) Scrobbler {
|
||||
return scrobbler{itunes, mr}
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository, npr NowPlayingRepository) Scrobbler {
|
||||
return scrobbler{itunes, mr, npr}
|
||||
}
|
||||
|
||||
type scrobbler struct {
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
npRepo NowPlayingRepository
|
||||
}
|
||||
|
||||
func (s scrobbler) Register(id string, playDate time.Time, submit bool) (*domain.MediaFile, error) {
|
||||
|
|
|
@ -17,9 +17,10 @@ func TestScrobbler(t *testing.T) {
|
|||
Init(t, false)
|
||||
|
||||
mfRepo := persistence.CreateMockMediaFileRepo()
|
||||
npRepo := engine.CreateMockNowPlayingRepo()
|
||||
itCtrl := &mockItunesControl{}
|
||||
|
||||
scrobbler := engine.NewScrobbler(itCtrl, mfRepo)
|
||||
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
|
||||
|
||||
Convey("Given a DB with one song", t, func() {
|
||||
mfRepo.SetData(`[{"Id":"2","Title":"Hands Of Time"}]`, 1)
|
||||
|
|
28
persistence/nowplaying_repository.go
Normal file
28
persistence/nowplaying_repository.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/deluan/gosonic/engine"
|
||||
)
|
||||
|
||||
type nowPlayingRepository struct {
|
||||
ledisRepository
|
||||
}
|
||||
|
||||
func NewNowPlayingRepository() engine.NowPlayingRepository {
|
||||
r := &nowPlayingRepository{}
|
||||
r.init("nnowplaying", &engine.NowPlayingInfo{})
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Add(id string) error {
|
||||
if id == "" {
|
||||
return errors.New("Id is required")
|
||||
}
|
||||
m := &engine.NowPlayingInfo{TrackId: id, Start: time.Now()}
|
||||
return r.saveOrUpdate(m.TrackId, m)
|
||||
}
|
||||
|
||||
var _ engine.NowPlayingRepository = (*nowPlayingRepository)(nil)
|
Loading…
Add table
Add a link
Reference in a new issue