From 8e482bc494e19ae3eedd30b156bbd30a32ccd668 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 1 Mar 2016 13:15:23 -0500 Subject: [PATCH] getIndexes returning list of artists and ignoredArticles --- api/get_indexes.go | 9 +++++++-- api/get_indexes_test.go | 9 ++++++--- api/responses/indexes.go | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/api/get_indexes.go b/api/get_indexes.go index c46831e3b..1a5b59c76 100644 --- a/api/get_indexes.go +++ b/api/get_indexes.go @@ -23,10 +23,15 @@ func (c *GetIndexesController) Get() { beego.Error("Error retrieving Indexes:", err) c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error"))) } - res := &responses.ArtistIndex{} - res.Index = make([]responses.Index, len(indexes)) + res := &responses.ArtistIndex{IgnoredArticles: beego.AppConfig.String("ignoredArticles")} + res.Index = make([]responses.IdxIndex, len(indexes)) for i, idx := range indexes { res.Index[i].Name = idx.Id + res.Index[i].Artists = make([]responses.IdxArtist, len(idx.Artists)) + for j, a := range idx.Artists { + res.Index[i].Artists[j].Id = a.ArtistId + res.Index[i].Artists[j].Name = a.Artist + } } c.Ctx.Output.Body(responses.NewXML(res)) diff --git a/api/get_indexes_test.go b/api/get_indexes_test.go index 7e0c01f92..4693c6179 100644 --- a/api/get_indexes_test.go +++ b/api/get_indexes_test.go @@ -43,15 +43,18 @@ func TestGetIndexes(t *testing.T) { So(err, ShouldBeNil) }) Convey("Then it should return an empty collection", func() { - So(w.Body.String(), ShouldContainSubstring, "") + So(w.Body.String(), ShouldContainSubstring, ``) }) }) Convey("When the index is not empty", func() { - mockRepo.data = makeMockData(`[{"Id": "A","Artists": []}]`, 2) + mockRepo.data = makeMockData(`[{"Id": "A","Artists": [ + {"ArtistId": "21", "Artist": "Afrolicious"} + ]}]`, 2) _, w := Get(AddParams("/rest/getIndexes.view"), "TestGetIndexes") Convey("Then it should return the the items in the response", func() { - So(w.Body.String(), ShouldContainSubstring, ``) + So(w.Body.String(), ShouldContainSubstring, + ``) }) }) Reset(func() { diff --git a/api/responses/indexes.go b/api/responses/indexes.go index 718cc9130..c8e793a1c 100644 --- a/api/responses/indexes.go +++ b/api/responses/indexes.go @@ -2,13 +2,21 @@ package responses import "encoding/xml" -type Index struct { - XMLName xml.Name `xml:"index"` - Name string `xml:"name,attr"` +type IdxArtist struct { + XMLName xml.Name `xml:"artist"` + Id string `xml:"id,attr"` + Name string `xml:"name,attr"` +} + +type IdxIndex struct { + XMLName xml.Name `xml:"index"` + Name string `xml:"name,attr"` + Artists []IdxArtist `xml:"index"` } type ArtistIndex struct { - XMLName xml.Name `xml:"indexes"` - Index []Index `xml:"indexes"` + XMLName xml.Name `xml:"indexes"` + Index []IdxIndex `xml:"indexes"` + IgnoredArticles string `xml:"ignoredArticles,attr"` }