getMusicDirectory bare bones for artists working

This commit is contained in:
Deluan
2016-03-02 22:22:31 -05:00
parent 4f5af423a8
commit 838d4bf38f
9 changed files with 158 additions and 42 deletions
+16 -2
View File
@@ -11,10 +11,12 @@ import (
type GetMusicDirectoryController struct {
BaseAPIController
artistRepo domain.ArtistRepository
albumRepo domain.AlbumRepository
}
func (c *GetMusicDirectoryController) Prepare() {
inject.ExtractAssignable(utils.Graph, &c.artistRepo)
inject.ExtractAssignable(utils.Graph, &c.albumRepo)
}
func (c *GetMusicDirectoryController) Get() {
@@ -32,10 +34,19 @@ func (c *GetMusicDirectoryController) Get() {
dir := &responses.Directory{}
if found {
a, _:= c.retrieveArtist(id)
a, albums := c.retrieveArtist(id)
dir.Id = a.Id
dir.Name = a.Name
dir.Child = make([]responses.Child, len(albums))
for i, al := range albums {
dir.Child[i].Id = al.Id
dir.Child[i].Title = al.Name
dir.Child[i].IsDir = true
dir.Child[i].Album = al.Name
dir.Child[i].Year = al.Year
dir.Child[i].Artist = a.Name
}
} else {
beego.Info("Artist", id, "not found")
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Directory not found")
@@ -54,6 +65,9 @@ func (c *GetMusicDirectoryController) retrieveArtist(id string) (a *domain.Artis
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
as = make([]domain.Album, 0)
if as, err = c.albumRepo.FindByArtist(id); err != nil {
beego.Error("Error reading Album from DB", err)
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
return
}