getNowPlaying.view working

This commit is contained in:
Deluan 2016-03-17 10:37:19 -04:00
parent 68c456e188
commit c4b660fce3
6 changed files with 25 additions and 12 deletions

View File

@ -90,8 +90,21 @@ func (c *AlbumListController) GetStarred() {
} }
func (c *AlbumListController) GetNowPlaying() { func (c *AlbumListController) GetNowPlaying() {
npInfos, err := c.listGen.GetNowPlaying()
if err != nil {
beego.Error("Error retrieving now playing list:", err)
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
response := c.NewEmpty() response := c.NewEmpty()
response.NowPlaying = &responses.NowPlaying{} response.NowPlaying = &responses.NowPlaying{}
//response.NowPlaying.Entry = make([]responses.NowPlayingEntry, 1) response.NowPlaying.Entry = make([]responses.NowPlayingEntry, len(*npInfos))
for i, entry := range *npInfos {
response.NowPlaying.Entry[i].Child = c.ToChild(entry)
response.NowPlaying.Entry[i].UserName = entry.UserName
response.NowPlaying.Entry[i].MinutesAgo = entry.MinutesAgo
response.NowPlaying.Entry[i].PlayerId = entry.PlayerId
response.NowPlaying.Entry[i].PlayerName = entry.PlayerName
}
c.SendResponse(response) c.SendResponse(response)
} }

View File

@ -24,8 +24,8 @@ func (c *MediaAnnotationController) Scrobble() {
time := c.ParamTime("time", time.Now()) time := c.ParamTime("time", time.Now())
submission := c.ParamBool("submission", false) submission := c.ParamBool("submission", false)
playerName := c.Data["c"].(string) playerName := c.ParamString("c")
username := c.Data["u"].(string) username := c.ParamString("u")
if submission { if submission {
mf, err := c.scrobbler.Register(id, time) mf, err := c.scrobbler.Register(id, time)

View File

@ -141,10 +141,10 @@ type Starred struct {
type NowPlayingEntry struct { type NowPlayingEntry struct {
Child Child
UserName string `xml:"username" json:"username,omitempty"` UserName string `xml:"username,attr" json:"username,omitempty"`
MinutesAgo int `xml:"minutesAgo" json:"minutesAgo,omitempty"` MinutesAgo int `xml:"minutesAgo,attr" json:"minutesAgo,omitempty"`
PlayerId int `xml:"playerId" json:"playerId,omitempty"` PlayerId int `xml:"playerId,attr" json:"playerId,omitempty"`
PlayerName string `xml:"playerName" json:"playerName,omitempty"` PlayerName string `xml:"playerName,attr" json:"playerName,omitempty"`
} }
type NowPlaying struct { type NowPlaying struct {

View File

@ -32,7 +32,6 @@ func checkParameters(c BaseAPIController) {
logWarn(c, fmt.Sprintf(`Missing required parameter "%s"`, p)) logWarn(c, fmt.Sprintf(`Missing required parameter "%s"`, p))
abortRequest(c, responses.ERROR_MISSING_PARAMETER) abortRequest(c, responses.ERROR_MISSING_PARAMETER)
} }
c.Data[p] = c.GetString(p)
} }
} }

View File

@ -4,10 +4,8 @@ import (
"math/rand" "math/rand"
"time" "time"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
"github.com/syndtr/goleveldb/leveldb/errors"
) )
// TODO Use Entries instead of Albums // TODO Use Entries instead of Albums
@ -103,11 +101,11 @@ func (g listGenerator) GetNowPlaying() (*Entries, error) {
return nil, err return nil, err
} }
entries[i] = FromMediaFile(mf) entries[i] = FromMediaFile(mf)
entries[i].UserName = beego.AppConfig.String("user") entries[i].UserName = np.Username
entries[i].MinutesAgo = int(time.Now().Sub(np.Start).Minutes()) entries[i].MinutesAgo = int(time.Now().Sub(np.Start).Minutes())
entries[i].PlayerId = np.PlayerId entries[i].PlayerId = np.PlayerId
entries[i].PlayerName = np.PlayerName entries[i].PlayerName = np.PlayerName
} }
return &entries, errors.New("Not implemented") return &entries, nil
} }

View File

@ -40,6 +40,9 @@ func (r *nowPlayingRepository) GetAll() (*[]engine.NowPlayingInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if val == nil {
return &[]engine.NowPlayingInfo{}, nil
}
info := &engine.NowPlayingInfo{} info := &engine.NowPlayingInfo{}
err = json.Unmarshal(val, info) err = json.Unmarshal(val, info)