Rename domain to model
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"container/list"
|
||||
"sync"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
var playerMap = sync.Map{}
|
||||
@@ -12,7 +12,7 @@ var playerMap = sync.Map{}
|
||||
type nowPlayingRepository struct{}
|
||||
|
||||
// TODO Make it persistent
|
||||
func NewNowPlayingRepository() domain.NowPlayingRepository {
|
||||
func NewNowPlayingRepository() model.NowPlayingRepository {
|
||||
r := &nowPlayingRepository{}
|
||||
return r
|
||||
}
|
||||
@@ -22,38 +22,38 @@ func (r *nowPlayingRepository) getList(id int) *list.List {
|
||||
return l.(*list.List)
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Enqueue(info *domain.NowPlayingInfo) error {
|
||||
func (r *nowPlayingRepository) Enqueue(info *model.NowPlayingInfo) error {
|
||||
l := r.getList(info.PlayerId)
|
||||
l.PushFront(info)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Dequeue(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Dequeue(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Back()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
l.Remove(e)
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Head(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Head(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Front()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Tail(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Tail(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Back()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Count(playerId int) (int64, error) {
|
||||
@@ -61,15 +61,15 @@ func (r *nowPlayingRepository) Count(playerId int) (int64, error) {
|
||||
return int64(l.Len()), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) GetAll() ([]*domain.NowPlayingInfo, error) {
|
||||
var all []*domain.NowPlayingInfo
|
||||
func (r *nowPlayingRepository) GetAll() ([]*model.NowPlayingInfo, error) {
|
||||
var all []*model.NowPlayingInfo
|
||||
playerMap.Range(func(playerId, l interface{}) bool {
|
||||
ll := l.(*list.List)
|
||||
e := ll.Front()
|
||||
all = append(all, e.Value.(*domain.NowPlayingInfo))
|
||||
all = append(all, e.Value.(*model.NowPlayingInfo))
|
||||
return true
|
||||
})
|
||||
return all, nil
|
||||
}
|
||||
|
||||
var _ domain.NowPlayingRepository = (*nowPlayingRepository)(nil)
|
||||
var _ model.NowPlayingRepository = (*nowPlayingRepository)(nil)
|
||||
|
||||
Reference in New Issue
Block a user