mirror of
https://github.com/navidrome/navidrome.git
synced 2025-12-23 23:18:05 -05:00
feat(server): add update and clear play queue endpoints to native API (#4215)
* Refactor queue payload handling * Refine queue update validation * refactor(queue): avoid loading tracks for validation * refactor/rename repository methods Signed-off-by: Deluan <deluan@navidrome.org> * more tests Signed-off-by: Deluan <deluan@navidrome.org> * refactor Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -8,11 +8,12 @@ import (
|
||||
|
||||
type MockPlayQueueRepo struct {
|
||||
model.PlayQueueRepository
|
||||
Queue *model.PlayQueue
|
||||
Err bool
|
||||
Queue *model.PlayQueue
|
||||
Err bool
|
||||
LastCols []string
|
||||
}
|
||||
|
||||
func (m *MockPlayQueueRepo) Store(q *model.PlayQueue) error {
|
||||
func (m *MockPlayQueueRepo) Store(q *model.PlayQueue, cols ...string) error {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
@@ -21,10 +22,11 @@ func (m *MockPlayQueueRepo) Store(q *model.PlayQueue) error {
|
||||
qCopy := *q
|
||||
qCopy.Items = copyItems
|
||||
m.Queue = &qCopy
|
||||
m.LastCols = cols
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockPlayQueueRepo) Retrieve(userId string) (*model.PlayQueue, error) {
|
||||
func (m *MockPlayQueueRepo) RetrieveWithMediaFiles(userId string) (*model.PlayQueue, error) {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
@@ -37,3 +39,27 @@ func (m *MockPlayQueueRepo) Retrieve(userId string) (*model.PlayQueue, error) {
|
||||
qCopy.Items = copyItems
|
||||
return &qCopy, nil
|
||||
}
|
||||
|
||||
func (m *MockPlayQueueRepo) Retrieve(userId string) (*model.PlayQueue, error) {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
if m.Queue == nil || m.Queue.UserID != userId {
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
copyItems := make(model.MediaFiles, len(m.Queue.Items))
|
||||
for i, t := range m.Queue.Items {
|
||||
copyItems[i] = model.MediaFile{ID: t.ID}
|
||||
}
|
||||
qCopy := *m.Queue
|
||||
qCopy.Items = copyItems
|
||||
return &qCopy, nil
|
||||
}
|
||||
|
||||
func (m *MockPlayQueueRepo) Clear(userId string) error {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
m.Queue = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user