mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-11 04:42:17 +03:00
Default sorts should be in the domain
This commit is contained in:
parent
fc6d49d34c
commit
5ca9680059
@ -1,5 +1,7 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
|
import "github.com/deluan/gosonic/utils"
|
||||||
|
|
||||||
type ArtistInfo struct {
|
type ArtistInfo struct {
|
||||||
ArtistId string
|
ArtistId string
|
||||||
Artist string
|
Artist string
|
||||||
@ -7,7 +9,14 @@ type ArtistInfo struct {
|
|||||||
|
|
||||||
type ArtistIndex struct {
|
type ArtistIndex struct {
|
||||||
Id string
|
Id string
|
||||||
Artists []ArtistInfo
|
Artists ArtistInfos
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArtistInfos []ArtistInfo
|
||||||
|
func (a ArtistInfos) Len() int { return len(a) }
|
||||||
|
func (a ArtistInfos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
func (a ArtistInfos) Less(i, j int) bool {
|
||||||
|
return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistIndexes []ArtistIndex
|
type ArtistIndexes []ArtistIndex
|
||||||
|
@ -33,6 +33,11 @@ func (mf *MediaFile) ContentType() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MediaFiles []MediaFile
|
type MediaFiles []MediaFile
|
||||||
|
func (a MediaFiles) Len() int { return len(a) }
|
||||||
|
func (a MediaFiles) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
func (a MediaFiles) Less(i, j int) bool {
|
||||||
|
return (a[i].DiscNumber * 1000 + a[i].TrackNumber) < (a[j].DiscNumber * 1000 + a[j].TrackNumber)
|
||||||
|
}
|
||||||
|
|
||||||
type MediaFileRepository interface {
|
type MediaFileRepository interface {
|
||||||
BaseRepository
|
BaseRepository
|
||||||
|
@ -3,7 +3,6 @@ package persistence
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
"github.com/deluan/gosonic/utils"
|
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
|
|||||||
if m.Id == "" {
|
if m.Id == "" {
|
||||||
return errors.New("Id is not set")
|
return errors.New("Id is not set")
|
||||||
}
|
}
|
||||||
sort.Sort(byArtistName(m.Artists))
|
sort.Sort(m.Artists)
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.Id, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,16 +36,4 @@ func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
|||||||
return indices, err
|
return indices, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type byArtistName []domain.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)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
@ -27,20 +27,8 @@ func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
|||||||
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
||||||
var mfs = make(domain.MediaFiles, 0)
|
var mfs = make(domain.MediaFiles, 0)
|
||||||
err := r.loadChildren("album", albumId, &mfs, "", false)
|
err := r.loadChildren("album", albumId, &mfs, "", false)
|
||||||
sort.Sort(byTrackNumber(mfs))
|
sort.Sort(mfs)
|
||||||
return mfs, err
|
return mfs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type byTrackNumber domain.MediaFiles
|
|
||||||
|
|
||||||
func (a byTrackNumber) Len() int {
|
|
||||||
return len(a)
|
|
||||||
}
|
|
||||||
func (a byTrackNumber) Swap(i, j int) {
|
|
||||||
a[i], a[j] = a[j], a[i]
|
|
||||||
}
|
|
||||||
func (a byTrackNumber) Less(i, j int) bool {
|
|
||||||
return (a[i].DiscNumber * 1000 + a[i].TrackNumber) < (a[j].DiscNumber * 1000 + a[j].TrackNumber)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ domain.MediaFileRepository = (*mediaFileRepository)(nil)
|
var _ domain.MediaFileRepository = (*mediaFileRepository)(nil)
|
Loading…
x
Reference in New Issue
Block a user