fix(subsonic): getRandomSongs with genre filter
fix https://github.com/dweymouth/supersonic/issues/577 Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/model/id"
|
"github.com/navidrome/navidrome/model/id"
|
||||||
@@ -53,17 +52,6 @@ var _ = Describe("MediaRepository", func() {
|
|||||||
Expect(err).To(MatchError(model.ErrNotFound))
|
Expect(err).To(MatchError(model.ErrNotFound))
|
||||||
})
|
})
|
||||||
|
|
||||||
XIt("filters by genre", func() {
|
|
||||||
Expect(mr.GetAll(model.QueryOptions{
|
|
||||||
Sort: "genre.name asc, title asc",
|
|
||||||
Filters: squirrel.Eq{"genre.name": "Rock"},
|
|
||||||
})).To(Equal(model.MediaFiles{
|
|
||||||
songDayInALife,
|
|
||||||
songAntenna,
|
|
||||||
songComeTogether,
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("Annotations", func() {
|
Context("Annotations", func() {
|
||||||
It("increments play count when the tracks does not have annotations", func() {
|
It("increments play count when the tracks does not have annotations", func() {
|
||||||
id := "incplay.firsttime"
|
id := "incplay.firsttime"
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func SongsByRandom(genre string, fromYear, toYear int) Options {
|
|||||||
}
|
}
|
||||||
ff := And{}
|
ff := And{}
|
||||||
if genre != "" {
|
if genre != "" {
|
||||||
ff = append(ff, Eq{"genre.name": genre})
|
ff = append(ff, filterByGenre(genre))
|
||||||
}
|
}
|
||||||
if fromYear != 0 {
|
if fromYear != 0 {
|
||||||
ff = append(ff, GtOrEq{"year": fromYear})
|
ff = append(ff, GtOrEq{"year": fromYear})
|
||||||
@@ -118,11 +118,15 @@ func SongWithLyrics(artist, title string) Options {
|
|||||||
|
|
||||||
func ByGenre(genre string) Options {
|
func ByGenre(genre string) Options {
|
||||||
return addDefaultFilters(Options{
|
return addDefaultFilters(Options{
|
||||||
Sort: "name asc",
|
Sort: "name asc",
|
||||||
Filters: persistence.Exists("json_tree(tags)", And{
|
Filters: filterByGenre(genre),
|
||||||
Like{"value": genre},
|
})
|
||||||
NotEq{"atom": nil},
|
}
|
||||||
}),
|
|
||||||
|
func filterByGenre(genre string) Sqlizer {
|
||||||
|
return persistence.Exists("json_tree(tags)", And{
|
||||||
|
Like{"value": genre},
|
||||||
|
NotEq{"atom": nil},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user