mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-19 05:17:41 +03:00
Make QueryOptions optional in AlbumRepository.GetAll
This commit is contained in:
parent
bfac3e3c91
commit
d4ed6a0569
@ -31,7 +31,7 @@ type AlbumRepository interface {
|
||||
Put(m *Album) error
|
||||
Get(id string) (*Album, error)
|
||||
FindByArtist(artistId string) (Albums, error)
|
||||
GetAll(QueryOptions) (Albums, error)
|
||||
GetAll(...QueryOptions) (Albums, error)
|
||||
PurgeInactive(active Albums) ([]string, error)
|
||||
GetAllIds() ([]string, error)
|
||||
GetStarred(QueryOptions) (Albums, error)
|
||||
|
@ -36,9 +36,9 @@ func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
||||
return as, err
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetAll(options domain.QueryOptions) (domain.Albums, error) {
|
||||
func (r *albumRepository) GetAll(options ...domain.QueryOptions) (domain.Albums, error) {
|
||||
var as = make(domain.Albums, 0)
|
||||
err := r.loadAll(&as, options)
|
||||
err := r.loadAll(&as, options...)
|
||||
return as, err
|
||||
}
|
||||
|
||||
|
@ -63,9 +63,9 @@ func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
||||
return r.toAlbums(albums)
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetAll(options domain.QueryOptions) (domain.Albums, error) {
|
||||
func (r *albumRepository) GetAll(options ...domain.QueryOptions) (domain.Albums, error) {
|
||||
var all []_Album
|
||||
err := r.getAll(&all, &options)
|
||||
err := r.getAll(&all, options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -82,7 +82,7 @@ func (r *albumRepository) toAlbums(all []_Album) (domain.Albums, error) {
|
||||
|
||||
func (r *albumRepository) GetAllIds() ([]string, error) {
|
||||
var all []_Album
|
||||
err := r.getAll(&all, &domain.QueryOptions{})
|
||||
err := r.getAll(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
||||
|
||||
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
||||
var all []_ArtistIndex
|
||||
err := r.getAll(&all, &domain.QueryOptions{})
|
||||
err := r.getAll(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (r *mediaFileRepository) GetStarred(options domain.QueryOptions) (domain.Me
|
||||
|
||||
func (r *mediaFileRepository) GetAllIds() ([]string, error) {
|
||||
var all []_MediaFile
|
||||
err := r.getAll(&all, &domain.QueryOptions{})
|
||||
err := r.getAll(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
||||
|
||||
func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlists, error) {
|
||||
var all []_Playlist
|
||||
err := r.getAll(&all, &options)
|
||||
err := r.getAll(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -91,21 +91,29 @@ func (r *stormRepository) execute(matcher q.Matcher, result interface{}, options
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *stormRepository) getAll(all interface{}, options *domain.QueryOptions) (err error) {
|
||||
if options.SortBy != "" {
|
||||
err = Db().AllByIndex(options.SortBy, all, stormOptions(options))
|
||||
func (r *stormRepository) getAll(all interface{}, options ...domain.QueryOptions) (err error) {
|
||||
o := domain.QueryOptions{}
|
||||
if len(options) > 0 {
|
||||
o = options[0]
|
||||
}
|
||||
if o.SortBy != "" {
|
||||
err = Db().AllByIndex(o.SortBy, all, stormOptions(o))
|
||||
} else {
|
||||
err = Db().All(all, stormOptions(options))
|
||||
err = Db().All(all, stormOptions(o))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func stormOptions(options *domain.QueryOptions) func(*index.Options) {
|
||||
func stormOptions(options ...domain.QueryOptions) func(*index.Options) {
|
||||
o := domain.QueryOptions{}
|
||||
if len(options) > 0 {
|
||||
o = options[0]
|
||||
}
|
||||
return func(opts *index.Options) {
|
||||
opts.Reverse = options.Desc
|
||||
opts.Skip = options.Offset
|
||||
if options.Size > 0 {
|
||||
opts.Limit = options.Size
|
||||
opts.Reverse = o.Desc
|
||||
opts.Skip = o.Offset
|
||||
if o.Size > 0 {
|
||||
opts.Limit = o.Size
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user