getIndexes returning list of artists and ignoredArticles
This commit is contained in:
+7
-2
@@ -23,10 +23,15 @@ func (c *GetIndexesController) Get() {
|
|||||||
beego.Error("Error retrieving Indexes:", err)
|
beego.Error("Error retrieving Indexes:", err)
|
||||||
c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error")))
|
c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error")))
|
||||||
}
|
}
|
||||||
res := &responses.ArtistIndex{}
|
res := &responses.ArtistIndex{IgnoredArticles: beego.AppConfig.String("ignoredArticles")}
|
||||||
res.Index = make([]responses.Index, len(indexes))
|
res.Index = make([]responses.IdxIndex, len(indexes))
|
||||||
for i, idx := range indexes {
|
for i, idx := range indexes {
|
||||||
res.Index[i].Name = idx.Id
|
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))
|
c.Ctx.Output.Body(responses.NewXML(res))
|
||||||
|
|||||||
@@ -43,15 +43,18 @@ func TestGetIndexes(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
Convey("Then it should return an empty collection", func() {
|
Convey("Then it should return an empty collection", func() {
|
||||||
So(w.Body.String(), ShouldContainSubstring, "<indexes></indexes>")
|
So(w.Body.String(), ShouldContainSubstring, `<indexes ignoredArticles="The El La Los Las Le Les Os As O A"></indexes>`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When the index is not empty", func() {
|
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")
|
_, w := Get(AddParams("/rest/getIndexes.view"), "TestGetIndexes")
|
||||||
|
|
||||||
Convey("Then it should return the the items in the response", func() {
|
Convey("Then it should return the the items in the response", func() {
|
||||||
So(w.Body.String(), ShouldContainSubstring, `<index name="A"></index>`)
|
So(w.Body.String(), ShouldContainSubstring,
|
||||||
|
`<indexes ignoredArticles="The El La Los Las Le Les Os As O A"><index name="A"><artist id="21" name="Afrolicious"></artist></index></indexes>`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
|
|||||||
@@ -2,13 +2,21 @@ package responses
|
|||||||
|
|
||||||
import "encoding/xml"
|
import "encoding/xml"
|
||||||
|
|
||||||
type Index struct {
|
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"`
|
XMLName xml.Name `xml:"index"`
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
|
Artists []IdxArtist `xml:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistIndex struct {
|
type ArtistIndex struct {
|
||||||
XMLName xml.Name `xml:"indexes"`
|
XMLName xml.Name `xml:"indexes"`
|
||||||
Index []Index `xml:"indexes"`
|
Index []IdxIndex `xml:"indexes"`
|
||||||
|
IgnoredArticles string `xml:"ignoredArticles,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user