navidrome/engine/ratings.go

40 lines
820 B
Go
Raw Normal View History

2016-03-23 17:46:54 -04:00
package engine
import (
2020-01-08 20:45:07 -05:00
"context"
2020-01-14 22:22:34 -05:00
"github.com/cloudsonic/sonic-server/model"
2016-03-23 17:46:54 -04:00
)
type Ratings interface {
2020-01-08 20:45:07 -05:00
SetStar(ctx context.Context, star bool, ids ...string) error
SetRating(ctx context.Context, id string, rating int) error
2016-03-23 17:46:54 -04:00
}
func NewRatings(ds model.DataStore) Ratings {
return &ratings{ds}
2016-03-23 17:46:54 -04:00
}
type ratings struct {
ds model.DataStore
2016-03-23 17:46:54 -04:00
}
2020-01-08 20:45:07 -05:00
func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
// TODO
2020-01-14 22:22:34 -05:00
return model.ErrNotFound
2016-03-23 19:37:48 -04:00
}
2020-01-08 20:45:07 -05:00
func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
return r.ds.WithTx(func(tx model.DataStore) error {
err := tx.MediaFile().SetStar(star, ids...)
if err != nil {
return err
}
err = tx.Album().SetStar(star, ids...)
if err != nil {
return err
}
err = tx.Artist().SetStar(star, ids...)
return err
})
2016-03-23 17:46:54 -04:00
}