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
+2 -2
View File
@@ -22,8 +22,8 @@ func (c *BrowsingController) Prepare() {
func (c *BrowsingController) GetMediaFolders() { func (c *BrowsingController) GetMediaFolders() {
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
} }
+2 -2
View File
@@ -22,8 +22,8 @@ func (c *PlaylistsController) GetAll() {
beego.Error(err) beego.Error(err)
c.SendError(responses.ERROR_GENERIC, "Internal error") c.SendError(responses.ERROR_GENERIC, "Internal error")
} }
playlists := make([]responses.Playlist, len(*allPls)) playlists := make([]responses.Playlist, len(allPls))
for i, f := range *allPls { for i, f := range allPls {
playlists[i].Id = f.Id playlists[i].Id = f.Id
playlists[i].Name = f.Name playlists[i].Name = f.Name
playlists[i].Comment = "Original: " + f.FullPath playlists[i].Comment = "Original: " + f.FullPath
+2 -2
View File
@@ -27,9 +27,9 @@ 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) ([]string, error) PurgeInactive(active Albums) ([]string, error)
GetAllIds() ([]string, error) GetAllIds() ([]string, error)
GetStarred(QueryOptions) (*Albums, error) GetStarred(QueryOptions) (Albums, error)
} }
+1 -1
View File
@@ -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) ([]string, error) PurgeInactive(active MediaFiles) ([]string, error)
} }
+1 -1
View File
@@ -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)
} }
+1 -1
View File
@@ -11,7 +11,7 @@ type PlaylistRepository interface {
BaseRepository BaseRepository
Put(m *Playlist) error Put(m *Playlist) error
Get(id string) (*Playlist, error) Get(id string) (*Playlist, error)
GetAll(options QueryOptions) (*Playlists, error) GetAll(options QueryOptions) (Playlists, error)
PurgeInactive(active Playlists) ([]string, error) PurgeInactive(active Playlists) ([]string, error)
} }
+10 -10
View File
@@ -13,7 +13,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)
} }
@@ -32,7 +32,7 @@ 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()
} }
@@ -84,21 +84,21 @@ func (c browser) Directory(id string) (*DirectoryInfo, error) {
return dir, nil 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 := &DirectoryInfo{Id: a.Id, Name: a.Name}
dir.Entries = make(Entries, len(*albums)) dir.Entries = make(Entries, len(albums))
for i, al := range *albums { for i, al := range albums {
dir.Entries[i] = FromAlbum(&al) dir.Entries[i] = FromAlbum(&al)
} }
return dir 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 := &DirectoryInfo{Id: al.Id, Name: al.Name}
dir.Entries = make(Entries, len(*tracks)) dir.Entries = make(Entries, len(tracks))
for i, mf := range *tracks { for i, mf := range tracks {
dir.Entries[i] = FromMediaFile(&mf) dir.Entries[i] = FromMediaFile(&mf)
} }
return dir return dir
@@ -122,7 +122,7 @@ func (c browser) isAlbum(id string) bool {
return found 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) 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)
@@ -135,7 +135,7 @@ func (c browser) retrieveArtist(id string) (a *domain.Artist, as *domain.Albums,
return 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) 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)
+2 -2
View File
@@ -80,9 +80,9 @@ func (g listGenerator) GetStarred() (Entries, error) {
if err != nil { if err != nil {
return nil, err 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) entries[i] = FromAlbum(&al)
} }
+2 -2
View File
@@ -5,7 +5,7 @@ import (
) )
type Playlists interface { type Playlists interface {
GetAll() (*domain.Playlists, error) GetAll() (domain.Playlists, error)
Get(id string) (*PlaylistInfo, error) Get(id string) (*PlaylistInfo, error)
} }
@@ -18,7 +18,7 @@ type playlists struct {
mfileRepo domain.MediaFileRepository mfileRepo domain.MediaFileRepository
} }
func (p playlists) GetAll() (*domain.Playlists, error) { func (p playlists) GetAll() (domain.Playlists, error) {
return p.plsRepo.GetAll(domain.QueryOptions{}) return p.plsRepo.GetAll(domain.QueryOptions{})
} }
+4 -4
View File
@@ -29,10 +29,10 @@ 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) {
@@ -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) var as = make(domain.Albums, 0)
err := r.loadRange("Starred", true, true, &as, options) err := r.loadRange("Starred", true, true, &as, options)
return &as, err return as, err
} }
var _ domain.AlbumRepository = (*albumRepository)(nil) var _ domain.AlbumRepository = (*albumRepository)(nil)
+2 -2
View File
@@ -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) ([]string, error) { func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) ([]string, error) {
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -59,7 +59,7 @@ func (m *MockAlbum) GetAll(qo domain.QueryOptions) (domain.Albums, 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!")
} }
@@ -72,5 +72,5 @@ func (m *MockAlbum) FindByArtist(artistId string) (*domain.Albums, error) {
} }
} }
return &res, nil return res, nil
} }
+2 -2
View File
@@ -52,7 +52,7 @@ func (m *MockMediaFile) Get(id string) (*domain.MediaFile, error) {
return nil, domain.ErrNotFound 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 { if m.err {
return nil, errors.New("Error!") return nil, errors.New("Error!")
} }
@@ -65,5 +65,5 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (*domain.MediaFiles, error)
} }
} }
return &res, nil return res, nil
} }
+2 -2
View File
@@ -29,10 +29,10 @@ func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
return rec.(*domain.Playlist), err 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) var as = make(domain.Playlists, 0)
err := r.loadAll(&as, options) err := r.loadAll(&as, options)
return &as, err return as, err
} }
func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) { func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) {