quintodrome/engine/ratings.go

41 lines
820 B
Go
Raw Normal View History

2016-03-23 13:46:54 -08:00
package engine
import (
2020-01-08 16:45:07 -09:00
"context"
2020-01-14 18:22:34 -09:00
"github.com/cloudsonic/sonic-server/model"
2016-03-23 13:46:54 -08:00
)
type Ratings interface {
2020-01-08 16:45:07 -09:00
SetStar(ctx context.Context, star bool, ids ...string) error
SetRating(ctx context.Context, id string, rating int) error
2016-03-23 13:46:54 -08:00
}
func NewRatings(ds model.DataStore) Ratings {
return &ratings{ds}
2016-03-23 13:46:54 -08:00
}
type ratings struct {
ds model.DataStore
2016-03-23 13:46:54 -08:00
}
2020-01-08 16:45:07 -09:00
func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
// TODO
2020-01-14 18:22:34 -09:00
return model.ErrNotFound
2016-03-23 15:37:48 -08:00
}
2020-01-08 16:45:07 -09: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 13:46:54 -08:00
}