Sorting artist index
This commit is contained in:
@@ -3,6 +3,8 @@ package repositories
|
||||
import (
|
||||
"github.com/deluan/gosonic/models"
|
||||
"errors"
|
||||
"sort"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
)
|
||||
|
||||
type ArtistIndex interface {
|
||||
@@ -36,8 +38,17 @@ func (r *artistIndex) Get(id string) (*models.ArtistIndex, error) {
|
||||
|
||||
func (r *artistIndex) GetAll() ([]models.ArtistIndex, error) {
|
||||
var indices = make([]models.ArtistIndex, 0)
|
||||
err := r.loadAll(&indices)
|
||||
err := r.loadAll(&indices, "")
|
||||
if err == nil {
|
||||
for _, idx := range indices {
|
||||
sort.Sort(byArtistName(idx.Artists))
|
||||
}
|
||||
}
|
||||
return indices, err
|
||||
}
|
||||
|
||||
type byArtistName []models.ArtistInfo
|
||||
|
||||
func (a byArtistName) Len() int { return len(a) }
|
||||
func (a byArtistName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byArtistName) Less(i, j int) bool { return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist) }
|
||||
|
||||
Reference in New Issue
Block a user