mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
address feedback (1)
This commit is contained in:
parent
1ad8b59dbc
commit
8d39d7797a
@ -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) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user