diff --git a/persistence/scrobble_repository.go b/persistence/scrobble_repository.go index 7238901cb..a1949e66f 100644 --- a/persistence/scrobble_repository.go +++ b/persistence/scrobble_repository.go @@ -16,9 +16,9 @@ type scrobbleRepository struct { } type dbScrobble struct { - MediaFileID string `structs:"media_file_id" json:"mediaFileId"` - RowId int64 `structs:"row_id" json:"rowId"` - SubmissionTime int64 `structs:"submission_time" json:"submissionTime"` + MediaFileID string `db:"media_file_id"` + RowId int64 `db:"row_id"` + SubmissionTime int64 `db:"submission_time"` } func (m dbScrobble) toScrobble() model.Scrobble { @@ -81,7 +81,10 @@ func (r *scrobbleRepository) RecordScrobble(mediaFileID string, submissionTime t } func (r *scrobbleRepository) CountAll(options ...model.QueryOptions) (int64, error) { - count := r.baseQuery(options...).RemoveColumns().Column("COUNT() as count").RemoveOffset().RemoveLimit().OrderBy("scrobbles.ROWID") + userID := loggedUser(r.ctx).ID + count := r.newSelect().Column("COUNT(*) as count").Where(Eq{"user_id": userID}) + // We do this instead of newSeelct, because we do not want to apply limit/offset/order + count = r.applyFilters(count, options...) var res struct{ Count int64 } err := r.queryOne(count, &res) return res.Count, err @@ -98,8 +101,8 @@ func (r *scrobbleRepository) Get(id string) (*model.Scrobble, error) { if err != nil { return nil, err } - model := res.toScrobble() - return &model, err + asModel := res.toScrobble() + return &asModel, err } func (r *scrobbleRepository) GetAll(options ...model.QueryOptions) (model.Scrobbles, error) { diff --git a/tests/mock_scrobble_repo.go b/tests/mock_scrobble_repo.go index 30fe4ee98..44d9728d8 100644 --- a/tests/mock_scrobble_repo.go +++ b/tests/mock_scrobble_repo.go @@ -15,9 +15,9 @@ type MockScrobbleRepo struct { } func (m *MockScrobbleRepo) Get(id string) (*model.Scrobble, error) { - for _, scrobble := range m.RecordedScrobbles { - if strconv.FormatInt(scrobble.ID, 10) == id { - return &scrobble, nil + for idx := range m.RecordedScrobbles { + if strconv.FormatInt(m.RecordedScrobbles[idx].ID, 10) == id { + return &m.RecordedScrobbles[idx], nil } }