More slices instead of pointers of slice

This commit is contained in:
Deluan 2016-03-20 13:14:04 -04:00
parent 3f0030738a
commit 21b39d922c
15 changed files with 37 additions and 37 deletions

View File

@ -22,8 +22,8 @@ func (c *BrowsingController) Prepare() {
func (c *BrowsingController) GetMediaFolders() {
mediaFolderList, _ := c.browser.MediaFolders()
folders := make([]responses.MusicFolder, len(*mediaFolderList))
for i, f := range *mediaFolderList {
folders := make([]responses.MusicFolder, len(mediaFolderList))
for i, f := range mediaFolderList {
folders[i].Id = f.Id
folders[i].Name = f.Name
}

View File

@ -22,8 +22,8 @@ func (c *PlaylistsController) GetAll() {
beego.Error(err)
c.SendError(responses.ERROR_GENERIC, "Internal error")
}
playlists := make([]responses.Playlist, len(*allPls))
for i, f := range *allPls {
playlists := make([]responses.Playlist, len(allPls))
for i, f := range allPls {
playlists[i].Id = f.Id
playlists[i].Name = f.Name
playlists[i].Comment = "Original: " + f.FullPath

View File

@ -27,9 +27,9 @@ type AlbumRepository interface {
BaseRepository
Put(m *Album) error
Get(id string) (*Album, error)
FindByArtist(artistId string) (*Albums, error)
FindByArtist(artistId string) (Albums, error)
GetAll(QueryOptions) (Albums, error)
PurgeInactive(active Albums) ([]string, error)
GetAllIds() ([]string, error)
GetStarred(QueryOptions) (*Albums, error)
GetStarred(QueryOptions) (Albums, error)
}

View File

@ -47,6 +47,6 @@ type MediaFileRepository interface {
BaseRepository
Put(m *MediaFile) error
Get(id string) (*MediaFile, error)
FindByAlbum(albumId string) (*MediaFiles, error)
FindByAlbum(albumId string) (MediaFiles, error)
PurgeInactive(active MediaFiles) ([]string, error)
}

View File

@ -9,5 +9,5 @@ type MediaFolder struct {
type MediaFolders []MediaFolder
type MediaFolderRepository interface {
GetAll() (*MediaFolders, error)
GetAll() (MediaFolders, error)
}

View File

@ -11,7 +11,7 @@ type PlaylistRepository interface {
BaseRepository
Put(m *Playlist) error
Get(id string) (*Playlist, error)
GetAll(options QueryOptions) (*Playlists, error)
GetAll(options QueryOptions) (Playlists, error)
PurgeInactive(active Playlists) ([]string, error)
}

View File

@ -13,7 +13,7 @@ import (
)
type Browser interface {
MediaFolders() (*domain.MediaFolders, error)
MediaFolders() (domain.MediaFolders, error)
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
Directory(id string) (*DirectoryInfo, error)
}
@ -32,7 +32,7 @@ type browser struct {
mfileRepo domain.MediaFileRepository
}
func (b browser) MediaFolders() (*domain.MediaFolders, error) {
func (b browser) MediaFolders() (domain.MediaFolders, error) {
return b.folderRepo.GetAll()
}
@ -84,21 +84,21 @@ func (c browser) Directory(id string) (*DirectoryInfo, error) {
return dir, nil
}
func (c browser) buildArtistDir(a *domain.Artist, albums *domain.Albums) *DirectoryInfo {
func (c browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
dir := &DirectoryInfo{Id: a.Id, Name: a.Name}
dir.Entries = make(Entries, len(*albums))
for i, al := range *albums {
dir.Entries = make(Entries, len(albums))
for i, al := range albums {
dir.Entries[i] = FromAlbum(&al)
}
return dir
}
func (c browser) buildAlbumDir(al *domain.Album, tracks *domain.MediaFiles) *DirectoryInfo {
func (c browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
dir := &DirectoryInfo{Id: al.Id, Name: al.Name}
dir.Entries = make(Entries, len(*tracks))
for i, mf := range *tracks {
dir.Entries = make(Entries, len(tracks))
for i, mf := range tracks {
dir.Entries[i] = FromMediaFile(&mf)
}
return dir
@ -122,7 +122,7 @@ func (c browser) isAlbum(id string) bool {
return found
}
func (c browser) retrieveArtist(id string) (a *domain.Artist, as *domain.Albums, err error) {
func (c browser) retrieveArtist(id string) (a *domain.Artist, as domain.Albums, err error) {
a, err = c.artistRepo.Get(id)
if err != nil {
err = fmt.Errorf("Error reading Artist %s from DB: %v", id, err)
@ -135,7 +135,7 @@ func (c browser) retrieveArtist(id string) (a *domain.Artist, as *domain.Albums,
return
}
func (c browser) retrieveAlbum(id string) (al *domain.Album, mfs *domain.MediaFiles, err error) {
func (c browser) retrieveAlbum(id string) (al *domain.Album, mfs domain.MediaFiles, err error) {
al, err = c.albumRepo.Get(id)
if err != nil {
err = fmt.Errorf("Error reading Album %s from DB: %v", id, err)

View File

@ -80,9 +80,9 @@ func (g listGenerator) GetStarred() (Entries, error) {
if err != nil {
return nil, err
}
entries := make(Entries, len(*albums))
entries := make(Entries, len(albums))
for i, al := range *albums {
for i, al := range albums {
entries[i] = FromAlbum(&al)
}

View File

@ -5,7 +5,7 @@ import (
)
type Playlists interface {
GetAll() (*domain.Playlists, error)
GetAll() (domain.Playlists, error)
Get(id string) (*PlaylistInfo, error)
}
@ -18,7 +18,7 @@ type playlists struct {
mfileRepo domain.MediaFileRepository
}
func (p playlists) GetAll() (*domain.Playlists, error) {
func (p playlists) GetAll() (domain.Playlists, error) {
return p.plsRepo.GetAll(domain.QueryOptions{})
}

View File

@ -29,10 +29,10 @@ func (r *albumRepository) Get(id string) (*domain.Album, error) {
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)
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) {
@ -63,10 +63,10 @@ func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error)
})
}
func (r *albumRepository) GetStarred(options domain.QueryOptions) (*domain.Albums, error) {
func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) {
var as = make(domain.Albums, 0)
err := r.loadRange("Starred", true, true, &as, options)
return &as, err
return as, err
}
var _ domain.AlbumRepository = (*albumRepository)(nil)

View File

@ -36,11 +36,11 @@ func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
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)
err := r.loadChildren("album", albumId, &mfs)
sort.Sort(mfs)
return &mfs, err
return mfs, err
}
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) ([]string, error) {

View File

@ -13,11 +13,11 @@ func NewMediaFolderRepository() domain.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")}
result := make(domain.MediaFolders, 1)
result[0] = mediaFolder
return &result, nil
return result, nil
}
var _ domain.MediaFolderRepository = (*mediaFolderRepository)(nil)

View File

@ -59,7 +59,7 @@ func (m *MockAlbum) GetAll(qo domain.QueryOptions) (domain.Albums, error) {
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 {
return nil, errors.New("Error!")
}
@ -72,5 +72,5 @@ func (m *MockAlbum) FindByArtist(artistId string) (*domain.Albums, error) {
}
}
return &res, nil
return res, nil
}

View File

@ -52,7 +52,7 @@ func (m *MockMediaFile) Get(id string) (*domain.MediaFile, error) {
return nil, domain.ErrNotFound
}
func (m *MockMediaFile) FindByAlbum(artistId string) (*domain.MediaFiles, error) {
func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error) {
if m.err {
return nil, errors.New("Error!")
}
@ -65,5 +65,5 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (*domain.MediaFiles, error)
}
}
return &res, nil
return res, nil
}

View File

@ -29,10 +29,10 @@ func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
return rec.(*domain.Playlist), err
}
func (r *playlistRepository) GetAll(options domain.QueryOptions) (*domain.Playlists, error) {
func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlists, error) {
var as = make(domain.Playlists, 0)
err := r.loadAll(&as, options)
return &as, err
return as, err
}
func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) {