mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-02 16:41:21 +03:00
Implemented getMediaFolders
This commit is contained in:
parent
59b541e45d
commit
2f3c9a7603
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/deluan/gosonic/controllers/responses"
|
"github.com/deluan/gosonic/controllers/responses"
|
||||||
|
"github.com/deluan/gosonic/repositories"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMusicFoldersController struct{ beego.Controller }
|
type GetMusicFoldersController struct{ beego.Controller }
|
||||||
@ -10,7 +11,17 @@ type GetMusicFoldersController struct{ beego.Controller }
|
|||||||
// @router /rest/getMusicFolders.view [get]
|
// @router /rest/getMusicFolders.view [get]
|
||||||
func (this *GetMusicFoldersController) Get() {
|
func (this *GetMusicFoldersController) Get() {
|
||||||
validate(this)
|
validate(this)
|
||||||
response := responses.NewError(responses.ERROR_GENERIC)
|
|
||||||
|
repository := new(repositories.MediaFolderRepository)
|
||||||
|
mediaFolderList := repository.GetAll()
|
||||||
|
folders := make([]responses.MusicFolder, len(mediaFolderList))
|
||||||
|
i := 0
|
||||||
|
for _, f := range mediaFolderList {
|
||||||
|
folders[i].Id = f.Id
|
||||||
|
folders[i].Name = f.Name
|
||||||
|
}
|
||||||
|
musicFolders := &responses.MusicFolders{Folders: folders}
|
||||||
|
response := responses.NewXML(musicFolders)
|
||||||
this.Ctx.Output.Body(response)
|
this.Ctx.Output.Body(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
controllers/responses/media_folders.go
Normal file
14
controllers/responses/media_folders.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package responses
|
||||||
|
|
||||||
|
import "encoding/xml"
|
||||||
|
|
||||||
|
type MusicFolder struct {
|
||||||
|
XMLName xml.Name `xml:"musicFolder"`
|
||||||
|
Id string `xml:"id,attr"`
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MusicFolders struct {
|
||||||
|
XMLName xml.Name `xml:"musicFolders"`
|
||||||
|
Folders []MusicFolder `xml:"musicFolders"`
|
||||||
|
}
|
7
models/media_folder.go
Normal file
7
models/media_folder.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type MediaFolder struct {
|
||||||
|
Id string
|
||||||
|
Name string
|
||||||
|
Path string
|
||||||
|
}
|
@ -1,3 +1,15 @@
|
|||||||
package repositories
|
package repositories
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/deluan/gosonic/models"
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MediaFolderRepository struct {}
|
||||||
|
|
||||||
|
func (*MediaFolderRepository) GetAll() []*models.MediaFolder {
|
||||||
|
mediaFolder := models.MediaFolder{Id: "1", Name: "iTunes Library", Path: beego.AppConfig.String("musicFolder")}
|
||||||
|
result := make([]*models.MediaFolder, 1)
|
||||||
|
result[0] = &mediaFolder
|
||||||
|
return result
|
||||||
|
}
|
@ -6,6 +6,7 @@ import (
|
|||||||
. "github.com/deluan/gosonic/tests"
|
. "github.com/deluan/gosonic/tests"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
"encoding/xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetMusicFolders(t *testing.T) {
|
func TestGetMusicFolders(t *testing.T) {
|
||||||
@ -15,6 +16,12 @@ func TestGetMusicFolders(t *testing.T) {
|
|||||||
Convey("Status code should be 200", func() {
|
Convey("Status code should be 200", func() {
|
||||||
So(w.Code, ShouldEqual, 200)
|
So(w.Code, ShouldEqual, 200)
|
||||||
})
|
})
|
||||||
|
Convey("The response should include the default folder", func() {
|
||||||
|
v := new(string)
|
||||||
|
err := xml.Unmarshal(w.Body.Bytes(), &v)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(w.Body.String(), ShouldContainSubstring, `musicFolder id="1" name="iTunes Library"`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user