Playlists support (99%) complete!

This commit is contained in:
Deluan
2016-03-24 13:28:20 -04:00
parent a27803a4d1
commit b9952bc3de
7 changed files with 110 additions and 8 deletions
+16
View File
@@ -39,6 +39,10 @@ func (c *BaseAPIController) ParamString(param string) string {
return c.Input().Get(param)
}
func (c *BaseAPIController) ParamStrings(param string) []string {
return c.Input()[param]
}
func (c *BaseAPIController) ParamTime(param string, def time.Time) time.Time {
var value int64
if c.Input().Get(param) == "" {
@@ -74,6 +78,18 @@ func (c *BaseAPIController) ParamInt(param string, def int) int {
return value
}
func (c *BaseAPIController) ParamInts(param string) []int {
pStr := c.Input()[param]
ints := make([]int, 0, len(pStr))
for _, s := range pStr {
i, err := strconv.ParseInt(s, 10, 32)
if err == nil {
ints = append(ints, int(i))
}
}
return ints
}
func (c *BaseAPIController) ParamBool(param string, def bool) bool {
value := def
if c.Input().Get(param) == "" {
+29 -1
View File
@@ -1,6 +1,8 @@
package api
import (
"fmt"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
@@ -27,7 +29,7 @@ func (c *PlaylistsController) GetAll() {
for i, p := range allPls {
playlists[i].Id = p.Id
playlists[i].Name = p.Name
playlists[i].Comment = "Original: " + p.FullPath
playlists[i].Comment = p.Comment
playlists[i].SongCount = len(p.Tracks)
playlists[i].Duration = p.Duration
playlists[i].Owner = p.Owner
@@ -77,6 +79,32 @@ func (c *PlaylistsController) Delete() {
c.SendEmptyResponse()
}
func (c *PlaylistsController) Update() {
playlistId := c.RequiredParamString("playlistId", "Required parameter playlistId is missing")
songsToAdd := c.ParamStrings("songIdToAdd")
songIndexesToRemove := c.ParamInts("songIndexToRemove")
var pname *string
if len(c.Input()["name"]) > 0 {
s := c.Input()["name"][0]
pname = &s
}
beego.Info(fmt.Sprintf("Updating playlist with id '%s'", playlistId))
if pname != nil {
beego.Debug(fmt.Sprintf(" -- New Name: '%s'", *pname))
}
beego.Debug(fmt.Sprintf(" -- Adding: '%v'", songsToAdd))
beego.Debug(fmt.Sprintf(" -- Removing: '%v'", songIndexesToRemove))
err := c.pls.Update(playlistId, pname, songsToAdd, songIndexesToRemove)
if err != nil {
beego.Error(err)
c.SendError(responses.ErrorGeneric, "Internal Error")
}
c.SendEmptyResponse()
}
func (c *PlaylistsController) buildPlaylist(d *engine.PlaylistInfo) *responses.PlaylistWithSongs {
pls := &responses.PlaylistWithSongs{}
pls.Id = d.Id