Introduced engine.Scrobbler
Also refactored mocks into their original packages, to avoid cyclic references. Is there a better way to have mocks in GoLang tests?
This commit is contained in:
+8
-15
@@ -6,38 +6,31 @@ import (
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/itunesbridge"
|
||||
"github.com/deluan/gosonic/engine"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
)
|
||||
|
||||
type MediaAnnotationController struct {
|
||||
BaseAPIController
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
scrobbler engine.Scrobbler
|
||||
}
|
||||
|
||||
func (c *MediaAnnotationController) Prepare() {
|
||||
utils.ResolveDependencies(&c.itunes, &c.mfRepo)
|
||||
utils.ResolveDependencies(&c.scrobbler)
|
||||
}
|
||||
|
||||
func (c *MediaAnnotationController) Scrobble() {
|
||||
id := c.RequiredParamString("id", "Required id parameter is missing")
|
||||
time := c.ParamTime("time", time.Now())
|
||||
submission := c.ParamBool("submission", true)
|
||||
|
||||
submission := c.ParamBool("submission", false)
|
||||
println(submission)
|
||||
if submission {
|
||||
mf, err := c.mfRepo.Get(id)
|
||||
if err != nil || mf == nil {
|
||||
beego.Error("Id", id, "not found!")
|
||||
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Id not found")
|
||||
}
|
||||
|
||||
beego.Info(fmt.Sprintf(`Scrobbling (%s) "%s" at %v`, id, mf.Title, time))
|
||||
if err := c.itunes.Scrobble(id, time); err != nil {
|
||||
mf, err := c.scrobbler.Register(id, time, true)
|
||||
if err != nil {
|
||||
beego.Error("Error scrobbling:", err)
|
||||
c.SendError(responses.ERROR_GENERIC, "Internal error")
|
||||
}
|
||||
beego.Info(fmt.Sprintf(`Scrobbled (%s) "%s" at %v`, id, mf.Title, time))
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
|
||||
Reference in New Issue
Block a user