Big Importer/Scanner refactor

This commit is contained in:
Deluan
2016-03-04 16:42:09 -05:00
parent 7225807bad
commit 766fdbc60c
8 changed files with 205 additions and 152 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
package persistence
import (
"errors"
"github.com/deluan/gosonic/domain"
)
@@ -16,7 +17,7 @@ func NewAlbumRepository() domain.AlbumRepository {
func (r *albumRepository) Put(m *domain.Album) error {
if m.Id == "" {
m.Id = r.NewId(m.ArtistId, m.Name)
return errors.New("Album Id is not set")
}
return r.saveOrUpdate(m.Id, m)
}
+3 -2
View File
@@ -1,6 +1,7 @@
package persistence
import (
"errors"
"github.com/deluan/gosonic/domain"
)
@@ -16,7 +17,7 @@ func NewArtistRepository() domain.ArtistRepository {
func (r *artistRepository) Put(m *domain.Artist) error {
if m.Id == "" {
m.Id = r.NewId(m.Name)
return errors.New("Artist Id is not set")
}
return r.saveOrUpdate(m.Id, m)
}
@@ -32,4 +33,4 @@ func (r *artistRepository) GetByName(name string) (*domain.Artist, error) {
return r.Get(id)
}
var _ domain.ArtistRepository = (*artistRepository)(nil)
var _ domain.ArtistRepository = (*artistRepository)(nil)
+3 -3
View File
@@ -18,7 +18,7 @@ func NewArtistIndexRepository() domain.ArtistIndexRepository {
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
if m.Id == "" {
return errors.New("Id is not set")
return errors.New("Index Id is not set")
}
sort.Sort(m.Artists)
return r.saveOrUpdate(m.Id, m)
@@ -32,8 +32,8 @@ func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
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
}
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
+4
View File
@@ -1,6 +1,7 @@
package persistence
import (
"errors"
"github.com/deluan/gosonic/domain"
"sort"
)
@@ -16,6 +17,9 @@ func NewMediaFileRepository() domain.MediaFileRepository {
}
func (r *mediaFileRepository) Put(m *domain.MediaFile) error {
if m.Id == "" {
return errors.New("MediaFile Id is not set")
}
return r.saveOrUpdate(m.Id, m)
}