Make QueryOptions optional in AlbumRepository.GetAll
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ type AlbumRepository interface {
|
|||||||
Put(m *Album) error
|
Put(m *Album) error
|
||||||
Get(id string) (*Album, error)
|
Get(id string) (*Album, error)
|
||||||
FindByArtist(artistId string) (Albums, error)
|
FindByArtist(artistId string) (Albums, error)
|
||||||
GetAll(QueryOptions) (Albums, error)
|
GetAll(...QueryOptions) (Albums, error)
|
||||||
PurgeInactive(active Albums) ([]string, error)
|
PurgeInactive(active Albums) ([]string, error)
|
||||||
GetAllIds() ([]string, error)
|
GetAllIds() ([]string, error)
|
||||||
GetStarred(QueryOptions) (Albums, error)
|
GetStarred(QueryOptions) (Albums, error)
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
|||||||
return as, err
|
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)
|
var as = make(domain.Albums, 0)
|
||||||
err := r.loadAll(&as, options)
|
err := r.loadAll(&as, options...)
|
||||||
return as, err
|
return as, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
|||||||
return r.toAlbums(albums)
|
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
|
var all []_Album
|
||||||
err := r.getAll(&all, &options)
|
err := r.getAll(&all, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ func (r *albumRepository) toAlbums(all []_Album) (domain.Albums, error) {
|
|||||||
|
|
||||||
func (r *albumRepository) GetAllIds() ([]string, error) {
|
func (r *albumRepository) GetAllIds() ([]string, error) {
|
||||||
var all []_Album
|
var all []_Album
|
||||||
err := r.getAll(&all, &domain.QueryOptions{})
|
err := r.getAll(&all)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
|||||||
|
|
||||||
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
||||||
var all []_ArtistIndex
|
var all []_ArtistIndex
|
||||||
err := r.getAll(&all, &domain.QueryOptions{})
|
err := r.getAll(&all)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func (r *mediaFileRepository) GetStarred(options domain.QueryOptions) (domain.Me
|
|||||||
|
|
||||||
func (r *mediaFileRepository) GetAllIds() ([]string, error) {
|
func (r *mediaFileRepository) GetAllIds() ([]string, error) {
|
||||||
var all []_MediaFile
|
var all []_MediaFile
|
||||||
err := r.getAll(&all, &domain.QueryOptions{})
|
err := r.getAll(&all)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlists, error) {
|
||||||
var all []_Playlist
|
var all []_Playlist
|
||||||
err := r.getAll(&all, &options)
|
err := r.getAll(&all)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,21 +91,29 @@ func (r *stormRepository) execute(matcher q.Matcher, result interface{}, options
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *stormRepository) getAll(all interface{}, options *domain.QueryOptions) (err error) {
|
func (r *stormRepository) getAll(all interface{}, options ...domain.QueryOptions) (err error) {
|
||||||
if options.SortBy != "" {
|
o := domain.QueryOptions{}
|
||||||
err = Db().AllByIndex(options.SortBy, all, stormOptions(options))
|
if len(options) > 0 {
|
||||||
|
o = options[0]
|
||||||
|
}
|
||||||
|
if o.SortBy != "" {
|
||||||
|
err = Db().AllByIndex(o.SortBy, all, stormOptions(o))
|
||||||
} else {
|
} else {
|
||||||
err = Db().All(all, stormOptions(options))
|
err = Db().All(all, stormOptions(o))
|
||||||
}
|
}
|
||||||
return
|
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) {
|
return func(opts *index.Options) {
|
||||||
opts.Reverse = options.Desc
|
opts.Reverse = o.Desc
|
||||||
opts.Skip = options.Offset
|
opts.Skip = o.Offset
|
||||||
if options.Size > 0 {
|
if o.Size > 0 {
|
||||||
opts.Limit = options.Size
|
opts.Limit = o.Size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user