Renamed persistence packages
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package db_ledis
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
)
|
||||
|
||||
type artistIndexRepository struct {
|
||||
ledisRepository
|
||||
}
|
||||
|
||||
func NewArtistIndexRepository() domain.ArtistIndexRepository {
|
||||
r := &artistIndexRepository{}
|
||||
r.init("index", &domain.ArtistIndex{})
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
|
||||
if m.ID == "" {
|
||||
return errors.New("index ID is not set")
|
||||
}
|
||||
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)
|
||||
return rec.(*domain.ArtistIndex), err
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
||||
var indices = make(domain.ArtistIndexes, 0)
|
||||
err := r.loadAll(&indices, domain.QueryOptions{Alpha: true})
|
||||
return indices, err
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) DeleteAll() error {
|
||||
var empty domain.ArtistIndexes
|
||||
_, err := r.purgeInactive(empty, func(e interface{}) string {
|
||||
return e.(domain.ArtistIndex).ID
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||
Reference in New Issue
Block a user