Converted all collections from repositories to *collections
This commit is contained in:
parent
e9ab07e4d3
commit
60d4cb5d9f
|
@ -34,8 +34,8 @@ func (c *GetIndexesController) Get() {
|
||||||
LastModified: fmt.Sprint(utils.ToMillis(lastModified)),
|
LastModified: fmt.Sprint(utils.ToMillis(lastModified)),
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Index = make([]responses.Index, len(indexes))
|
res.Index = make([]responses.Index, len(*indexes))
|
||||||
for i, idx := range indexes {
|
for i, idx := range *indexes {
|
||||||
res.Index[i].Name = idx.Id
|
res.Index[i].Name = idx.Id
|
||||||
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
|
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
|
||||||
for j, a := range idx.Artists {
|
for j, a := range idx.Artists {
|
||||||
|
|
|
@ -18,8 +18,8 @@ func (c *GetMusicFoldersController) Prepare() {
|
||||||
|
|
||||||
func (c *GetMusicFoldersController) Get() {
|
func (c *GetMusicFoldersController) Get() {
|
||||||
mediaFolderList, _ := c.browser.MediaFolders()
|
mediaFolderList, _ := c.browser.MediaFolders()
|
||||||
folders := make([]responses.MusicFolder, len(mediaFolderList))
|
folders := make([]responses.MusicFolder, len(*mediaFolderList))
|
||||||
for i, f := range mediaFolderList {
|
for i, f := range *mediaFolderList {
|
||||||
folders[i].Id = f.Id
|
folders[i].Id = f.Id
|
||||||
folders[i].Name = f.Name
|
folders[i].Name = f.Name
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ type AlbumRepository interface {
|
||||||
BaseRepository
|
BaseRepository
|
||||||
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) error
|
PurgeInactive(active *Albums) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ type ArtistIndex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistInfos []ArtistInfo
|
type ArtistInfos []ArtistInfo
|
||||||
func (a ArtistInfos) Len() int { return len(a) }
|
|
||||||
|
func (a ArtistInfos) Len() int { return len(a) }
|
||||||
func (a ArtistInfos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ArtistInfos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ArtistInfos) Less(i, j int) bool {
|
func (a ArtistInfos) Less(i, j int) bool {
|
||||||
return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist)
|
return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist)
|
||||||
|
@ -25,5 +26,5 @@ type ArtistIndexRepository interface {
|
||||||
BaseRepository
|
BaseRepository
|
||||||
Put(m *ArtistIndex) error
|
Put(m *ArtistIndex) error
|
||||||
Get(id string) (*ArtistIndex, error)
|
Get(id string) (*ArtistIndex, error)
|
||||||
GetAll() (ArtistIndexes, error)
|
GetAll() (*ArtistIndexes, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,6 @@ type MediaFileRepository interface {
|
||||||
BaseRepository
|
BaseRepository
|
||||||
Put(m *MediaFile) error
|
Put(m *MediaFile) error
|
||||||
Get(id string) (*MediaFile, error)
|
Get(id string) (*MediaFile, error)
|
||||||
FindByAlbum(albumId string) (MediaFiles, error)
|
FindByAlbum(albumId string) (*MediaFiles, error)
|
||||||
PurgeInactive(active *MediaFiles) error
|
PurgeInactive(active *MediaFiles) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ type MediaFolder struct {
|
||||||
type MediaFolders []MediaFolder
|
type MediaFolders []MediaFolder
|
||||||
|
|
||||||
type MediaFolderRepository interface {
|
type MediaFolderRepository interface {
|
||||||
GetAll() (MediaFolders, error)
|
GetAll() (*MediaFolders, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Browser interface {
|
type Browser interface {
|
||||||
MediaFolders() (domain.MediaFolders, error)
|
MediaFolders() (*domain.MediaFolders, error)
|
||||||
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
|
Indexes(ifModifiedSince time.Time) (*domain.ArtistIndexes, time.Time, error)
|
||||||
Directory(id string) (*DirectoryInfo, error)
|
Directory(id string) (*DirectoryInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,17 +36,17 @@ type browser struct {
|
||||||
mfileRepo domain.MediaFileRepository
|
mfileRepo domain.MediaFileRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b browser) MediaFolders() (domain.MediaFolders, error) {
|
func (b browser) MediaFolders() (*domain.MediaFolders, error) {
|
||||||
return b.folderRepo.GetAll()
|
return b.folderRepo.GetAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b browser) Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error) {
|
func (b browser) Indexes(ifModifiedSince time.Time) (*domain.ArtistIndexes, time.Time, error) {
|
||||||
l, err := b.propRepo.DefaultGet(consts.LastScan, "-1")
|
l, err := b.propRepo.DefaultGet(consts.LastScan, "-1")
|
||||||
ms, _ := strconv.ParseInt(l, 10, 64)
|
ms, _ := strconv.ParseInt(l, 10, 64)
|
||||||
lastModified := utils.ToTime(ms)
|
lastModified := utils.ToTime(ms)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.ArtistIndexes{}, time.Time{}, errors.New(fmt.Sprintf("Error retrieving LastScan property: %v", err))
|
return &domain.ArtistIndexes{}, time.Time{}, errors.New(fmt.Sprintf("Error retrieving LastScan property: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastModified.After(ifModifiedSince) {
|
if lastModified.After(ifModifiedSince) {
|
||||||
|
@ -54,7 +54,7 @@ func (b browser) Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.
|
||||||
return indexes, lastModified, err
|
return indexes, lastModified, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain.ArtistIndexes{}, lastModified, nil
|
return &domain.ArtistIndexes{}, lastModified, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Child struct {
|
type Child struct {
|
||||||
|
@ -107,11 +107,11 @@ func (c browser) Directory(id string) (*DirectoryInfo, error) {
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c browser) buildArtistDir(a *domain.Artist, albums []domain.Album) *DirectoryInfo {
|
func (c browser) buildArtistDir(a *domain.Artist, albums *domain.Albums) *DirectoryInfo {
|
||||||
dir := &DirectoryInfo{Id: a.Id, Name: a.Name}
|
dir := &DirectoryInfo{Id: a.Id, Name: a.Name}
|
||||||
|
|
||||||
dir.Children = make([]Child, len(albums))
|
dir.Children = make([]Child, len(*albums))
|
||||||
for i, al := range albums {
|
for i, al := range *albums {
|
||||||
dir.Children[i].Id = al.Id
|
dir.Children[i].Id = al.Id
|
||||||
dir.Children[i].Title = al.Name
|
dir.Children[i].Title = al.Name
|
||||||
dir.Children[i].IsDir = true
|
dir.Children[i].IsDir = true
|
||||||
|
@ -129,11 +129,11 @@ func (c browser) buildArtistDir(a *domain.Artist, albums []domain.Album) *Direct
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c browser) buildAlbumDir(al *domain.Album, tracks []domain.MediaFile) *DirectoryInfo {
|
func (c browser) buildAlbumDir(al *domain.Album, tracks *domain.MediaFiles) *DirectoryInfo {
|
||||||
dir := &DirectoryInfo{Id: al.Id, Name: al.Name}
|
dir := &DirectoryInfo{Id: al.Id, Name: al.Name}
|
||||||
|
|
||||||
dir.Children = make([]Child, len(tracks))
|
dir.Children = make([]Child, len(*tracks))
|
||||||
for i, mf := range tracks {
|
for i, mf := range *tracks {
|
||||||
dir.Children[i].Id = mf.Id
|
dir.Children[i].Id = mf.Id
|
||||||
dir.Children[i].Title = mf.Title
|
dir.Children[i].Title = mf.Title
|
||||||
dir.Children[i].IsDir = false
|
dir.Children[i].IsDir = false
|
||||||
|
@ -176,7 +176,7 @@ func (c browser) isAlbum(id string) bool {
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c browser) retrieveArtist(id string) (a *domain.Artist, as []domain.Album, err error) {
|
func (c browser) retrieveArtist(id string) (a *domain.Artist, as *domain.Albums, err error) {
|
||||||
a, err = c.artistRepo.Get(id)
|
a, err = c.artistRepo.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Error reading Artist %s from DB: %v", id, err)
|
err = fmt.Errorf("Error reading Artist %s from DB: %v", id, err)
|
||||||
|
@ -189,7 +189,7 @@ func (c browser) retrieveArtist(id string) (a *domain.Artist, as []domain.Album,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c browser) retrieveAlbum(id string) (al *domain.Album, mfs []domain.MediaFile, err error) {
|
func (c browser) retrieveAlbum(id string) (al *domain.Album, mfs *domain.MediaFiles, err error) {
|
||||||
al, err = c.albumRepo.Get(id)
|
al, err = c.albumRepo.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Error reading Album %s from DB: %v", id, err)
|
err = fmt.Errorf("Error reading Album %s from DB: %v", id, err)
|
||||||
|
|
|
@ -22,8 +22,7 @@ type listGenerator struct {
|
||||||
func (g listGenerator) query(qo domain.QueryOptions, offset int, size int) (*domain.Albums, error) {
|
func (g listGenerator) query(qo domain.QueryOptions, offset int, size int) (*domain.Albums, error) {
|
||||||
qo.Offset = offset
|
qo.Offset = offset
|
||||||
qo.Size = size
|
qo.Size = size
|
||||||
als, err := g.albumRepo.GetAll(qo)
|
return g.albumRepo.GetAll(qo)
|
||||||
return &als, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g listGenerator) GetNewest(offset int, size int) (*domain.Albums, error) {
|
func (g listGenerator) GetNewest(offset int, size int) (*domain.Albums, error) {
|
||||||
|
|
|
@ -29,16 +29,16 @@ func (r *albumRepository) Get(id string) (*domain.Album, error) {
|
||||||
return rec.(*domain.Album), err
|
return rec.(*domain.Album), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
func (r *albumRepository) FindByArtist(artistId string) (*domain.Albums, error) {
|
||||||
var as = make(domain.Albums, 0)
|
var as = make(domain.Albums, 0)
|
||||||
err := r.loadChildren("artist", artistId, &as, domain.QueryOptions{SortBy: "Year"})
|
err := r.loadChildren("artist", artistId, &as, domain.QueryOptions{SortBy: "Year"})
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *albumRepository) PurgeInactive(active *domain.Albums) error {
|
func (r *albumRepository) PurgeInactive(active *domain.Albums) error {
|
||||||
|
|
|
@ -2,8 +2,9 @@ package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/deluan/gosonic/domain"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/deluan/gosonic/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
type artistIndexRepository struct {
|
type artistIndexRepository struct {
|
||||||
|
@ -30,10 +31,10 @@ func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
||||||
return rec.(*domain.ArtistIndex), err
|
return rec.(*domain.ArtistIndex), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
func (r *artistIndexRepository) GetAll() (*domain.ArtistIndexes, error) {
|
||||||
var indices = make(domain.ArtistIndexes, 0)
|
var indices = make(domain.ArtistIndexes, 0)
|
||||||
err := r.loadAll(&indices, domain.QueryOptions{Alpha: true})
|
err := r.loadAll(&indices, domain.QueryOptions{Alpha: true})
|
||||||
return indices, err
|
return &indices, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
"github.com/deluan/gosonic/tests"
|
"github.com/deluan/gosonic/tests"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIndexRepository(t *testing.T) {
|
func TestIndexRepository(t *testing.T) {
|
||||||
|
@ -56,7 +57,7 @@ func TestIndexRepository(t *testing.T) {
|
||||||
So(indices, ShouldHaveLength, 4)
|
So(indices, ShouldHaveLength, 4)
|
||||||
})
|
})
|
||||||
Convey("And the values should be retrieved", func() {
|
Convey("And the values should be retrieved", func() {
|
||||||
for _, e := range indices {
|
for _, e := range *indices {
|
||||||
So(e.Id, ShouldBeIn, []string{"1", "2", "3", "4"})
|
So(e.Id, ShouldBeIn, []string{"1", "2", "3", "4"})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,11 +36,11 @@ func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
||||||
return mf, nil
|
return mf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
func (r *mediaFileRepository) FindByAlbum(albumId string) (*domain.MediaFiles, error) {
|
||||||
var mfs = make(domain.MediaFiles, 0)
|
var mfs = make(domain.MediaFiles, 0)
|
||||||
err := r.loadChildren("album", albumId, &mfs)
|
err := r.loadChildren("album", albumId, &mfs)
|
||||||
sort.Sort(mfs)
|
sort.Sort(mfs)
|
||||||
return mfs, err
|
return &mfs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mediaFileRepository) PurgeInactive(active *domain.MediaFiles) error {
|
func (r *mediaFileRepository) PurgeInactive(active *domain.MediaFiles) error {
|
||||||
|
|
|
@ -13,11 +13,11 @@ func NewMediaFolderRepository() domain.MediaFolderRepository {
|
||||||
return &mediaFolderRepository{}
|
return &mediaFolderRepository{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*mediaFolderRepository) GetAll() (domain.MediaFolders, error) {
|
func (*mediaFolderRepository) GetAll() (*domain.MediaFolders, error) {
|
||||||
mediaFolder := domain.MediaFolder{Id: "0", Name: "iTunes Library", Path: beego.AppConfig.String("musicFolder")}
|
mediaFolder := domain.MediaFolder{Id: "0", Name: "iTunes Library", Path: beego.AppConfig.String("musicFolder")}
|
||||||
result := make(domain.MediaFolders, 1)
|
result := make(domain.MediaFolders, 1)
|
||||||
result[0] = mediaFolder
|
result[0] = mediaFolder
|
||||||
return result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ domain.MediaFolderRepository = (*mediaFolderRepository)(nil)
|
var _ domain.MediaFolderRepository = (*mediaFolderRepository)(nil)
|
||||||
|
|
|
@ -48,15 +48,15 @@ func (m *MockAlbum) Get(id string) (*domain.Album, error) {
|
||||||
return m.data[id], nil
|
return m.data[id], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) GetAll(qo domain.QueryOptions) (domain.Albums, error) {
|
func (m *MockAlbum) GetAll(qo domain.QueryOptions) (*domain.Albums, error) {
|
||||||
m.Options = qo
|
m.Options = qo
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
return m.all, nil
|
return &m.all, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
|
func (m *MockAlbum) FindByArtist(artistId string) (*domain.Albums, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -69,5 +69,5 @@ func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,9 +30,9 @@ func (m *MockArtistIndex) SetData(j string, length int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockArtistIndex) GetAll() (domain.ArtistIndexes, error) {
|
func (m *MockArtistIndex) GetAll() (*domain.ArtistIndexes, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
return m.data, nil
|
return &m.data, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ func (m *MockMediaFile) Get(id string) (*domain.MediaFile, error) {
|
||||||
return mf, nil
|
return mf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error) {
|
func (m *MockMediaFile) FindByAlbum(artistId string) (*domain.MediaFiles, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -62,5 +63,5 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue