From 375fd300452d1e9b31efe3776a3cfb5588e2606d Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 1 Mar 2016 09:17:28 -0500 Subject: [PATCH] Fixed AlbumId generation. Some code cleanup --- .gopmfile | 3 ++- api/get_license_test.go | 2 +- api/get_music_folders_test.go | 2 +- api/ping_test.go | 2 +- main.go | 28 --------------------------- repositories/album_repository.go | 10 ++-------- repositories/index_repository.go | 18 +++++++++++------ repositories/index_repository_test.go | 2 +- 8 files changed, 20 insertions(+), 47 deletions(-) diff --git a/.gopmfile b/.gopmfile index 229c4850c..86cb5b50a 100644 --- a/.gopmfile +++ b/.gopmfile @@ -6,6 +6,7 @@ github.com/astaxie/beego = commit:92d0b9a github.com/dhowden/itl = commit:35d15a3 github.com/siddontang/ledisdb = commit:713b229 github.com/smartystreets/goconvey = commit:899ed5a +github.com/karlkfi/inject = commit:fe06da2 [res] -include = conf \ No newline at end of file +include = conf diff --git a/api/get_license_test.go b/api/get_license_test.go index 8fc4078ec..22bd9ecf6 100644 --- a/api/get_license_test.go +++ b/api/get_license_test.go @@ -12,7 +12,7 @@ func TestGetLicense(t *testing.T) { _, w := Get(AddParams("/rest/getLicense.view"), "TestGetLicense") - Convey("Subject: GetLicense Endpoint\n", t, func() { + Convey("Subject: GetLicense Endpoint", t, func() { Convey("Status code should be 200", func() { So(w.Code, ShouldEqual, 200) }) diff --git a/api/get_music_folders_test.go b/api/get_music_folders_test.go index a7ae9a039..cfd727b64 100644 --- a/api/get_music_folders_test.go +++ b/api/get_music_folders_test.go @@ -13,7 +13,7 @@ func TestGetMusicFolders(t *testing.T) { _, w := Get(AddParams("/rest/getMusicFolders.view"), "TestGetMusicFolders") - Convey("Subject: GetMusicFolders Endpoint\n", t, func() { + Convey("Subject: GetMusicFolders Endpoint", t, func() { Convey("Status code should be 200", func() { So(w.Code, ShouldEqual, 200) }) diff --git a/api/ping_test.go b/api/ping_test.go index f44c012bd..4f78345de 100644 --- a/api/ping_test.go +++ b/api/ping_test.go @@ -13,7 +13,7 @@ func TestPing(t *testing.T) { _, w := Get(AddParams("/rest/ping.view"), "TestPing") - Convey("Subject: Ping Endpoint\n", t, func() { + Convey("Subject: Ping Endpoint", t, func() { Convey("Status code should be 200", func() { So(w.Code, ShouldEqual, 200) }) diff --git a/main.go b/main.go index 7fdbb9cc9..ba007e2da 100644 --- a/main.go +++ b/main.go @@ -2,38 +2,10 @@ package main import ( _ "github.com/deluan/gosonic/routers" - "github.com/astaxie/beego" ) func main() { - //// open a new index - //itunes.LoadFolder("iTunes Music Library.xml") - // - //mapping := bleve.NewIndexMapping() - //index, err := bleve.New("example.bleve", mapping) - //if (err != nil) { - // index, err = bleve.Open("example.bleve") - //} - // - //// index some data - //doc := struct { - // Id string - // Value string - //}{ - // Id: "01", - // Value: "deluan cotts quintao", - //} - //err = index.Index("01", doc) - //fmt.Println(err) - // - //// search for some text - //query := bleve.NewMatchQuery("*cotts*") - //search := bleve.NewSearchRequest(query) - //searchResults, err := index.Search(search) - //fmt.Println(err) - //fmt.Println(searchResults.Hits) - if beego.BConfig.RunMode == "dev" { beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" diff --git a/repositories/album_repository.go b/repositories/album_repository.go index 1303b4d5a..81ef54324 100644 --- a/repositories/album_repository.go +++ b/repositories/album_repository.go @@ -16,7 +16,7 @@ func NewAlbumRepository() *Album { func (r *Album) Put(m *models.Album) error { if m.Id == "" { - m.Id = r.NewId(m.Name) + m.Id = r.NewId(m.ArtistId, m.Name) } return r.saveOrUpdate(m.Id, m) } @@ -25,10 +25,4 @@ func (r *Album) Get(id string) (*models.Album, error) { var rec interface{} rec, err := r.readEntity(id) return rec.(*models.Album), err -} - -func (r *Album) GetByName(name string) (*models.Album, error) { - id := r.NewId(name) - return r.Get(id) -} - +} \ No newline at end of file diff --git a/repositories/index_repository.go b/repositories/index_repository.go index a9cd83110..26e3fff01 100644 --- a/repositories/index_repository.go +++ b/repositories/index_repository.go @@ -5,30 +5,36 @@ import ( "errors" ) -type ArtistIndex struct { +type ArtistIndex interface { + Put(m *models.ArtistIndex) error + Get(id string) (*models.ArtistIndex, error) + GetAll() ([]models.ArtistIndex, error) +} + +type artistIndex struct { BaseRepository } -func NewArtistIndexRepository() *ArtistIndex { - r := &ArtistIndex{} +func NewArtistIndexRepository() ArtistIndex { + r := &artistIndex{} r.init("index", &models.ArtistIndex{}) return r } -func (r *ArtistIndex) Put(m *models.ArtistIndex) error { +func (r *artistIndex) Put(m *models.ArtistIndex) error { if m.Id == "" { return errors.New("Id is not set") } return r.saveOrUpdate(m.Id, m) } -func (r *ArtistIndex) Get(id string) (*models.ArtistIndex, error) { +func (r *artistIndex) Get(id string) (*models.ArtistIndex, error) { var rec interface{} rec, err := r.readEntity(id) return rec.(*models.ArtistIndex), err } -func (r *ArtistIndex) GetAll() ([]models.ArtistIndex, error) { +func (r *artistIndex) GetAll() ([]models.ArtistIndex, error) { var indices = make([]models.ArtistIndex, 0) err := r.loadAll(&indices) return indices, err diff --git a/repositories/index_repository_test.go b/repositories/index_repository_test.go index b184e04a2..e8a6f6b68 100644 --- a/repositories/index_repository_test.go +++ b/repositories/index_repository_test.go @@ -23,7 +23,7 @@ func TestIndexRepository(t *testing.T) { So(s, shouldBeEqual, i) }) - Convey("Put() should return error if Id is not set", func() { + Convey("Method Put() should return error if Id is not set", func() { i := &models.ArtistIndex{} err := repo.Put(i)