Reimplemented GetAlbumList&type=random and GetRandomSongs (now with filter by genres)

This commit is contained in:
Deluan
2020-01-21 08:49:43 -05:00
parent 6cd758faa0
commit de0816da67
9 changed files with 80 additions and 54 deletions
+18
View File
@@ -79,6 +79,24 @@ func (r *albumRepository) GetAll(options ...model.QueryOptions) (model.Albums, e
return r.toAlbums(all), nil
}
// TODO Keep order when paginating
func (r *albumRepository) GetRandom(options ...model.QueryOptions) (model.Albums, error) {
sq := r.newRawQuery(options...)
switch r.ormer.Driver().Type() {
case orm.DRMySQL:
sq = sq.OrderBy("RAND()")
default:
sq = sq.OrderBy("RANDOM()")
}
sql, args, err := sq.ToSql()
if err != nil {
return nil, err
}
var results []album
_, err = r.ormer.Raw(sql, args...).QueryRows(&results)
return r.toAlbums(results), err
}
func (r *albumRepository) toAlbums(all []album) model.Albums {
result := make(model.Albums, len(all))
for i, a := range all {