navidrome/persistence/index_repository.go

41 lines
922 B
Go
Raw Normal View History

2016-03-02 15:07:24 +01:00
package persistence
import (
"errors"
2016-03-02 19:18:39 +01:00
"sort"
"github.com/deluan/gosonic/domain"
)
type artistIndexRepository struct {
ledisRepository
}
2016-03-02 15:07:24 +01:00
func NewArtistIndexRepository() domain.ArtistIndexRepository {
r := &artistIndexRepository{}
2016-03-02 15:07:24 +01:00
r.init("index", &domain.ArtistIndex{})
return r
}
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
if m.Id == "" {
2016-03-04 22:42:09 +01:00
return errors.New("Index Id is not set")
}
2016-03-04 03:42:12 +01:00
sort.Sort(m.Artists)
return r.saveOrUpdate(m.Id, m)
}
func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
var rec interface{}
rec, err := r.readEntity(id)
2016-03-02 15:07:24 +01:00
return rec.(*domain.ArtistIndex), err
2016-02-29 14:34:57 +01:00
}
func (r *artistIndexRepository) GetAll() (*domain.ArtistIndexes, error) {
2016-03-04 03:01:55 +01:00
var indices = make(domain.ArtistIndexes, 0)
2016-03-04 22:42:09 +01:00
err := r.loadAll(&indices, domain.QueryOptions{Alpha: true})
return &indices, err
2016-02-29 14:34:57 +01:00
}
2016-03-04 22:42:09 +01:00
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)