mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
* initial scrobble api * feat: add scrobble retrieval api * address feedback (1) * fix spelling * be explicit about get * add primary key field, update index, remove rowid references * use unix timestamp for input and output --------- Co-authored-by: Deluan Quintão <deluan@navidrome.org>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/request"
|
|
)
|
|
|
|
type MockScrobbleRepo struct {
|
|
RecordedScrobbles []model.Scrobble
|
|
ctx context.Context
|
|
}
|
|
|
|
func (m *MockScrobbleRepo) Get(id string) (*model.Scrobble, error) {
|
|
for idx := range m.RecordedScrobbles {
|
|
if strconv.FormatInt(m.RecordedScrobbles[idx].ID, 10) == id {
|
|
return &m.RecordedScrobbles[idx], nil
|
|
}
|
|
}
|
|
|
|
return nil, model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockScrobbleRepo) GetAll(options ...model.QueryOptions) (model.Scrobbles, error) {
|
|
return m.RecordedScrobbles, nil
|
|
}
|
|
|
|
func (m *MockScrobbleRepo) CountAll(options ...model.QueryOptions) (int64, error) {
|
|
return int64(len(m.RecordedScrobbles)), nil
|
|
}
|
|
|
|
func (m *MockScrobbleRepo) RecordScrobble(fileID string, submissionTime time.Time) error {
|
|
user, _ := request.UserFrom(m.ctx)
|
|
m.RecordedScrobbles = append(m.RecordedScrobbles, model.Scrobble{
|
|
MediaFileID: fileID,
|
|
UserID: user.ID,
|
|
SubmissionTime: submissionTime.Unix(),
|
|
})
|
|
return nil
|
|
}
|
|
|
|
var _ model.ScrobbleRepository = (*MockScrobbleRepo)(nil)
|