Add Stars to the DB, including Artists! Only if DevUseFolderScanner is true

This commit is contained in:
Deluan
2020-01-18 20:03:52 -05:00
parent a4b75fd69d
commit 128e165aba
18 changed files with 161 additions and 30 deletions
+19 -1
View File
@@ -27,7 +27,7 @@ type album struct {
Duration int ``
Rating int `orm:"index"`
Genre string `orm:"index"`
StarredAt time.Time `orm:"null"`
StarredAt time.Time `orm:"index;null"`
CreatedAt time.Time `orm:"null"`
UpdatedAt time.Time `orm:"null"`
}
@@ -118,6 +118,9 @@ group by album_id order by f.id`, strings.Join(ids, "','"))
if al.Compilation {
al.AlbumArtist = "Various Artists"
}
if al.AlbumArtist == "" {
al.AlbumArtist = al.Artist
}
if al.CurrentId != "" {
toUpdate = append(toUpdate, al.album)
} else {
@@ -172,6 +175,21 @@ func (r *albumRepository) GetStarred(options ...model.QueryOptions) (model.Album
return r.toAlbums(starred), nil
}
func (r *albumRepository) SetStar(starred bool, ids ...string) error {
if len(ids) == 0 {
return model.ErrNotFound
}
var starredAt time.Time
if starred {
starredAt = time.Now()
}
_, err := r.newQuery(Db()).Filter("id__in", ids).Update(orm.Params{
"starred": starred,
"starred_at": starredAt,
})
return err
}
func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, error) {
if len(q) <= 2 {
return nil, nil
+30 -3
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strings"
"time"
"github.com/astaxie/beego/orm"
"github.com/cloudsonic/sonic-server/conf"
@@ -13,9 +14,11 @@ import (
)
type artist struct {
ID string `orm:"pk;column(id)"`
Name string `orm:"index"`
AlbumCount int `orm:"column(album_count)"`
ID string `orm:"pk;column(id)"`
Name string `orm:"index"`
AlbumCount int `orm:"column(album_count)"`
Starred bool `orm:"index"`
StarredAt time.Time `orm:"index;null"`
}
type artistRepository struct {
@@ -152,6 +155,30 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id
return err
}
func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Artists, error) {
var starred []artist
_, err := r.newQuery(Db(), options...).Filter("starred", true).All(&starred)
if err != nil {
return nil, err
}
return r.toArtists(starred), nil
}
func (r *artistRepository) SetStar(starred bool, ids ...string) error {
if len(ids) == 0 {
return model.ErrNotFound
}
var starredAt time.Time
if starred {
starredAt = time.Now()
}
_, err := r.newQuery(Db()).Filter("id__in", ids).Update(orm.Params{
"starred": starred,
"starred_at": starredAt,
})
return err
}
func (r *artistRepository) PurgeInactive(activeList model.Artists) error {
return withTx(func(o orm.Ormer) error {
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {
+24 -1
View File
@@ -32,7 +32,7 @@ type mediaFile struct {
PlayDate time.Time `orm:"null"`
Rating int `orm:"index"`
Starred bool `orm:"index"`
StarredAt time.Time `orm:"null"`
StarredAt time.Time `orm:"index;null"`
CreatedAt time.Time `orm:"null"`
UpdatedAt time.Time `orm:"null"`
}
@@ -135,6 +135,29 @@ func (r *mediaFileRepository) GetStarred(options ...model.QueryOptions) (model.M
return r.toMediaFiles(starred), nil
}
func (r *mediaFileRepository) SetStar(starred bool, ids ...string) error {
if len(ids) == 0 {
return model.ErrNotFound
}
var starredAt time.Time
if starred {
starredAt = time.Now()
}
_, err := r.newQuery(Db()).Filter("id__in", ids).Update(orm.Params{
"starred": starred,
"starred_at": starredAt,
})
return err
}
func (r *mediaFileRepository) SetRating(rating int, ids ...string) error {
if len(ids) == 0 {
return model.ErrNotFound
}
_, err := r.newQuery(Db()).Filter("id__in", ids).Update(orm.Params{"rating": rating})
return err
}
func (r *mediaFileRepository) PurgeInactive(activeList model.MediaFiles) error {
return withTx(func(o orm.Ormer) error {
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {