Refactored object mapping

This commit is contained in:
Deluan
2016-03-11 09:10:40 -05:00
parent 94ccad225d
commit 3a3bd91324
7 changed files with 144 additions and 101 deletions
+24
View File
@@ -7,6 +7,7 @@ import (
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
)
@@ -70,3 +71,26 @@ func (c *BaseAPIController) SendResponse(response responses.Subsonic) {
c.ServeXML()
}
}
func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
n := responses.Child{}
n.Id = entry.Id
n.Title = entry.Title
n.IsDir = entry.IsDir
n.Parent = entry.Parent
n.Album = entry.Album
n.Year = entry.Year
n.Artist = entry.Artist
n.Genre = entry.Genre
n.CoverArt = entry.CoverArt
n.Track = entry.Track
n.Duration = entry.Duration
n.Size = entry.Size
n.Suffix = entry.Suffix
n.BitRate = entry.BitRate
n.ContentType = entry.ContentType
if !entry.Starred.IsZero() {
n.Starred = &entry.Starred
}
return n
}
+3 -20
View File
@@ -84,26 +84,9 @@ func (c *BrowsingController) GetDirectory() {
func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.Directory {
dir := &responses.Directory{Id: d.Id, Name: d.Name}
dir.Child = make([]responses.Child, len(d.Children))
for i, child := range d.Children {
dir.Child[i].Id = child.Id
dir.Child[i].Title = child.Title
dir.Child[i].IsDir = child.IsDir
dir.Child[i].Parent = child.Parent
dir.Child[i].Album = child.Album
dir.Child[i].Year = child.Year
dir.Child[i].Artist = child.Artist
dir.Child[i].Genre = child.Genre
dir.Child[i].CoverArt = child.CoverArt
dir.Child[i].Track = child.Track
dir.Child[i].Duration = child.Duration
dir.Child[i].Size = child.Size
dir.Child[i].Suffix = child.Suffix
dir.Child[i].BitRate = child.BitRate
dir.Child[i].ContentType = child.ContentType
if !child.Starred.IsZero() {
dir.Child[i].Starred = &child.Starred
}
dir.Child = make([]responses.Child, len(d.Entries))
for i, entry := range d.Entries {
dir.Child[i] = c.ToChild(entry)
}
return dir
}
+17 -2
View File
@@ -29,15 +29,30 @@ func (c *SearchingController) Search2() {
as, err := c.search.SearchArtist(query, artistOffset, artistCount)
if err != nil {
beego.Error("Error searching for Artists:", err)
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
//als, err := c.search.SearchAlbum(query, albumOffset, albumCount)
//if err != nil {
// beego.Error("Error searching for Albums:", err)
//}
//mfs, err := c.search.SearchSong(query, songOffset, songCount)
//if err != nil {
// beego.Error("Error searching for MediaFiles:", err)
//}
response := c.NewEmpty()
searchResult2 := &responses.SearchResult2{}
searchResult2.Artist = make([]responses.Artist, len(*as))
for i, a := range *as {
searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Name}
searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Title}
}
//searchResult2.Album = make([]responses.Child, len(*as))
//for i, a := range *as {
// searchResult2.Album[i] = responses.Child{Id: a.Id, Name: a.Name}
//}
//searchResult2.Artist = make([]responses.Artist, len(*as))
//for i, a := range *as {
// searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Name}
//}
response.SearchResult2 = searchResult2
c.SendResponse(response)
}