Indexes using slices instead of pointers of slice

This commit is contained in:
Deluan 2016-03-20 13:08:24 -04:00
parent 27b7b7ce08
commit 3f0030738a
6 changed files with 12 additions and 12 deletions

View File

@ -47,8 +47,8 @@ func (c *BrowsingController) GetIndexes() {
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 {

View File

@ -26,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)
} }

View File

@ -14,7 +14,7 @@ import (
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,13 +36,13 @@ 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 nil, time.Time{}, errors.New(fmt.Sprintf("Error retrieving LastScan property: %v", err))
} }
if lastModified.After(ifModifiedSince) { if lastModified.After(ifModifiedSince) {
@ -50,7 +50,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 nil, lastModified, nil
} }
type DirectoryInfo struct { type DirectoryInfo struct {

View File

@ -31,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)

View File

@ -57,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"})
} }
}) })

View File

@ -30,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
} }