Fixed AlbumId generation. Some code cleanup

This commit is contained in:
Deluan 2016-03-01 09:17:28 -05:00
parent 20650ed3fd
commit 375fd30045
8 changed files with 20 additions and 47 deletions

View file

@ -6,6 +6,7 @@ github.com/astaxie/beego = commit:92d0b9a
github.com/dhowden/itl = commit:35d15a3 github.com/dhowden/itl = commit:35d15a3
github.com/siddontang/ledisdb = commit:713b229 github.com/siddontang/ledisdb = commit:713b229
github.com/smartystreets/goconvey = commit:899ed5a github.com/smartystreets/goconvey = commit:899ed5a
github.com/karlkfi/inject = commit:fe06da2
[res] [res]
include = conf include = conf

View file

@ -12,7 +12,7 @@ func TestGetLicense(t *testing.T) {
_, w := Get(AddParams("/rest/getLicense.view"), "TestGetLicense") _, 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() { Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200) So(w.Code, ShouldEqual, 200)
}) })

View file

@ -13,7 +13,7 @@ func TestGetMusicFolders(t *testing.T) {
_, w := Get(AddParams("/rest/getMusicFolders.view"), "TestGetMusicFolders") _, 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() { Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200) So(w.Code, ShouldEqual, 200)
}) })

View file

@ -13,7 +13,7 @@ func TestPing(t *testing.T) {
_, w := Get(AddParams("/rest/ping.view"), "TestPing") _, 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() { Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200) So(w.Code, ShouldEqual, 200)
}) })

28
main.go
View file

@ -2,38 +2,10 @@ package main
import ( import (
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
"github.com/astaxie/beego" "github.com/astaxie/beego"
) )
func main() { 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" { if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

View file

@ -16,7 +16,7 @@ func NewAlbumRepository() *Album {
func (r *Album) Put(m *models.Album) error { func (r *Album) Put(m *models.Album) error {
if m.Id == "" { if m.Id == "" {
m.Id = r.NewId(m.Name) m.Id = r.NewId(m.ArtistId, m.Name)
} }
return r.saveOrUpdate(m.Id, m) return r.saveOrUpdate(m.Id, m)
} }
@ -25,10 +25,4 @@ func (r *Album) Get(id string) (*models.Album, error) {
var rec interface{} var rec interface{}
rec, err := r.readEntity(id) rec, err := r.readEntity(id)
return rec.(*models.Album), err return rec.(*models.Album), err
} }
func (r *Album) GetByName(name string) (*models.Album, error) {
id := r.NewId(name)
return r.Get(id)
}

View file

@ -5,30 +5,36 @@ import (
"errors" "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 BaseRepository
} }
func NewArtistIndexRepository() *ArtistIndex { func NewArtistIndexRepository() ArtistIndex {
r := &ArtistIndex{} r := &artistIndex{}
r.init("index", &models.ArtistIndex{}) r.init("index", &models.ArtistIndex{})
return r return r
} }
func (r *ArtistIndex) Put(m *models.ArtistIndex) error { func (r *artistIndex) Put(m *models.ArtistIndex) error {
if m.Id == "" { if m.Id == "" {
return errors.New("Id is not set") return errors.New("Id is not set")
} }
return r.saveOrUpdate(m.Id, m) 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{} var rec interface{}
rec, err := r.readEntity(id) rec, err := r.readEntity(id)
return rec.(*models.ArtistIndex), err 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) var indices = make([]models.ArtistIndex, 0)
err := r.loadAll(&indices) err := r.loadAll(&indices)
return indices, err return indices, err

View file

@ -23,7 +23,7 @@ func TestIndexRepository(t *testing.T) {
So(s, shouldBeEqual, i) 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{} i := &models.ArtistIndex{}
err := repo.Put(i) err := repo.Put(i)