move the id type into spec

This commit is contained in:
sentriz
2020-05-03 00:59:19 +01:00
committed by Senan Kelly
parent 26457aae6c
commit 1ef2d43d39
9 changed files with 167 additions and 136 deletions

View File

@@ -11,6 +11,9 @@ import (
"strings"
"time"
// TODO: remove this dep
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
"go.senan.xyz/gonic/server/mime"
)
@@ -46,6 +49,10 @@ type Artist struct {
AlbumCount int `sql:"-"`
}
func (a *Artist) SID() specid.ID {
return specid.ID{Type: specid.Artist, Value: a.ID}
}
func (a *Artist) IndexName() string {
if len(a.NameUDec) > 0 {
return a.NameUDec
@@ -85,6 +92,18 @@ type Track struct {
TagBrainzID string `sql:"default: null"`
}
func (t *Track) SID() specid.ID {
return specid.ID{Type: specid.Track, Value: t.ID}
}
func (t *Track) AlbumSID() specid.ID {
return specid.ID{Type: specid.Album, Value: t.AlbumID}
}
func (t *Track) ArtistSID() specid.ID {
return specid.ID{Type: specid.Artist, Value: t.ArtistID}
}
func (t *Track) Ext() string {
longExt := path.Ext(t.Filename)
if len(longExt) < 1 {
@@ -157,6 +176,14 @@ type Album struct {
ReceivedTags bool `gorm:"-"`
}
func (a *Album) SID() specid.ID {
return specid.ID{Type: specid.Album, Value: a.ID}
}
func (a *Album) ParentSID() specid.ID {
return specid.ID{Type: specid.Album, Value: a.ParentID}
}
func (a *Album) IndexRightPath() string {
if len(a.RightPathUDec) > 0 {
return a.RightPathUDec