Moved properties to engine layer

This commit is contained in:
Deluan 2016-03-08 18:40:16 -05:00
parent 067517a916
commit 8607e25c90
8 changed files with 20 additions and 18 deletions

View file

@ -2,9 +2,9 @@ package api
import ( import (
"fmt" "fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine" "github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject" "github.com/karlkfi/inject"
@ -12,13 +12,11 @@ import (
type GetIndexesController struct { type GetIndexesController struct {
BaseAPIController BaseAPIController
properties domain.PropertyRepository browser engine.Browser
browser engine.Browser
} }
func (c *GetIndexesController) Prepare() { func (c *GetIndexesController) Prepare() {
inject.ExtractAssignable(utils.Graph, &c.browser) inject.ExtractAssignable(utils.Graph, &c.browser)
inject.ExtractAssignable(utils.Graph, &c.properties)
} }
// TODO: Shortcuts amd validate musicFolder parameter // TODO: Shortcuts amd validate musicFolder parameter

View file

@ -6,6 +6,7 @@ import (
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/consts" "github.com/deluan/gosonic/consts"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/tests/mocks" "github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
@ -24,7 +25,7 @@ func TestGetIndexes(t *testing.T) {
return mockRepo return mockRepo
}) })
propRepo := mocks.CreateMockPropertyRepo() propRepo := mocks.CreateMockPropertyRepo()
utils.DefineSingleton(new(domain.PropertyRepository), func() domain.PropertyRepository { utils.DefineSingleton(new(engine.PropertyRepository), func() engine.PropertyRepository {
return propRepo return propRepo
}) })

View file

@ -10,12 +10,12 @@ import (
func init() { func init() {
// Persistence // Persistence
utils.DefineSingleton(new(domain.ArtistIndexRepository), persistence.NewArtistIndexRepository) utils.DefineSingleton(new(domain.ArtistIndexRepository), persistence.NewArtistIndexRepository)
utils.DefineSingleton(new(domain.PropertyRepository), persistence.NewPropertyRepository)
utils.DefineSingleton(new(domain.MediaFolderRepository), persistence.NewMediaFolderRepository) utils.DefineSingleton(new(domain.MediaFolderRepository), persistence.NewMediaFolderRepository)
utils.DefineSingleton(new(domain.ArtistRepository), persistence.NewArtistRepository) utils.DefineSingleton(new(domain.ArtistRepository), persistence.NewArtistRepository)
utils.DefineSingleton(new(domain.AlbumRepository), persistence.NewAlbumRepository) utils.DefineSingleton(new(domain.AlbumRepository), persistence.NewAlbumRepository)
utils.DefineSingleton(new(domain.MediaFileRepository), persistence.NewMediaFileRepository) utils.DefineSingleton(new(domain.MediaFileRepository), persistence.NewMediaFileRepository)
// Engine (Use cases) // Engine (Use cases)
utils.DefineSingleton(new(engine.PropertyRepository), persistence.NewPropertyRepository)
utils.DefineSingleton(new(engine.Browser), engine.NewBrowser) utils.DefineSingleton(new(engine.Browser), engine.NewBrowser)
} }

View file

@ -22,13 +22,13 @@ type Browser interface {
Directory(id string) (*DirectoryInfo, error) Directory(id string) (*DirectoryInfo, error)
} }
func NewBrowser(pr domain.PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository, func NewBrowser(pr PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain.MediaFileRepository) Browser { ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain.MediaFileRepository) Browser {
return browser{pr, fr, ir, ar, alr, mr} return browser{pr, fr, ir, ar, alr, mr}
} }
type browser struct { type browser struct {
propRepo domain.PropertyRepository propRepo PropertyRepository
folderRepo domain.MediaFolderRepository folderRepo domain.MediaFolderRepository
indexRepo domain.ArtistIndexRepository indexRepo domain.ArtistIndexRepository
artistRepo domain.ArtistRepository artistRepo domain.ArtistRepository

View file

@ -1,4 +1,4 @@
package domain package engine
type Property struct { type Property struct {
Id string Id string

View file

@ -2,21 +2,22 @@ package persistence
import ( import (
"errors" "errors"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
) )
type propertyRepository struct { type propertyRepository struct {
ledisRepository ledisRepository
} }
func NewPropertyRepository() domain.PropertyRepository { func NewPropertyRepository() engine.PropertyRepository {
r := &propertyRepository{} r := &propertyRepository{}
r.init("property", &domain.Property{}) r.init("property", &engine.Property{})
return r return r
} }
func (r *propertyRepository) Put(id string, value string) error { func (r *propertyRepository) Put(id string, value string) error {
m := &domain.Property{Id: id, Value: value} m := &engine.Property{Id: id, Value: value}
if m.Id == "" { if m.Id == "" {
return errors.New("Id is required") return errors.New("Id is required")
} }
@ -26,7 +27,7 @@ func (r *propertyRepository) Put(id string, value string) error {
func (r *propertyRepository) Get(id string) (string, error) { func (r *propertyRepository) Get(id string) (string, error) {
var rec interface{} var rec interface{}
rec, err := r.readEntity(id) rec, err := r.readEntity(id)
return rec.(*domain.Property).Value, err return rec.(*engine.Property).Value, err
} }
func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string, error) { func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string, error) {
@ -39,4 +40,4 @@ func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string,
return v, err return v, err
} }
var _ domain.PropertyRepository = (*propertyRepository)(nil) var _ engine.PropertyRepository = (*propertyRepository)(nil)

View file

@ -9,6 +9,7 @@ import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/deluan/gosonic/consts" "github.com/deluan/gosonic/consts"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/persistence" "github.com/deluan/gosonic/persistence"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
) )
@ -45,7 +46,7 @@ type Importer struct {
albumRepo domain.AlbumRepository albumRepo domain.AlbumRepository
artistRepo domain.ArtistRepository artistRepo domain.ArtistRepository
idxRepo domain.ArtistIndexRepository idxRepo domain.ArtistIndexRepository
propertyRepo domain.PropertyRepository propertyRepo engine.PropertyRepository
lastScan time.Time lastScan time.Time
} }

View file

@ -2,7 +2,8 @@ package mocks
import ( import (
"errors" "errors"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
) )
func CreateMockPropertyRepo() *MockProperty { func CreateMockPropertyRepo() *MockProperty {
@ -10,7 +11,7 @@ func CreateMockPropertyRepo() *MockProperty {
} }
type MockProperty struct { type MockProperty struct {
domain.PropertyRepository engine.PropertyRepository
data map[string]string data map[string]string
err bool err bool
} }