Scrobble accepts multiple ids

This commit is contained in:
Deluan 2016-03-21 19:35:40 -04:00
parent 12b1002d51
commit 8e1736703d
2 changed files with 59 additions and 27 deletions

View file

@ -5,6 +5,8 @@ import (
"fmt"
"time"
"strconv"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
@ -25,6 +27,14 @@ func (c *BaseAPIController) RequiredParamString(param string, msg string) string
return p
}
func (c *BaseAPIController) RequiredParamStrings(param string, msg string) []string {
ps := c.Input()[param]
if len(ps) == 0 {
c.SendError(responses.ERROR_MISSING_PARAMETER, msg)
}
return ps
}
func (c *BaseAPIController) ParamString(param string) string {
return c.Input().Get(param)
}
@ -38,6 +48,18 @@ func (c *BaseAPIController) ParamTime(param string, def time.Time) time.Time {
return utils.ToTime(value)
}
func (c *BaseAPIController) ParamTimes(param string) []time.Time {
pStr := c.Input()[param]
times := make([]time.Time, len(pStr))
for i, t := range pStr {
ti, err := strconv.ParseInt(t, 10, 64)
if err == nil {
times[i] = utils.ToTime(ti)
}
}
return times
}
func (c *BaseAPIController) ParamInt(param string, def int) int {
value := def
c.Ctx.Input.Bind(&value, param)
@ -59,7 +81,7 @@ func (c *BaseAPIController) SendError(errorCode int, message ...interface{}) {
if len(message) == 0 {
msg = responses.ErrorMsg(errorCode)
} else {
msg = fmt.Sprintf(message[0].(string), message[1:len(message)]...)
msg = fmt.Sprintf(message[0].(string), message[1:]...)
}
response.Error = &responses.Error{Code: errorCode, Message: msg}