createPlaylist

This commit is contained in:
Deluan
2016-03-24 12:06:39 -04:00
parent 5b2ecc39ca
commit 52850c6ef0
4 changed files with 48 additions and 2 deletions
+17 -2
View File
@@ -1,19 +1,25 @@
package engine
import (
"fmt"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/itunesbridge"
)
type Playlists interface {
GetAll() (domain.Playlists, error)
Get(id string) (*PlaylistInfo, error)
Create(name string, ids []string) error
}
func NewPlaylists(pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {
return &playlists{pr, mr}
func NewPlaylists(itunes itunesbridge.ItunesControl, pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {
return &playlists{itunes, pr, mr}
}
type playlists struct {
itunes itunesbridge.ItunesControl
plsRepo domain.PlaylistRepository
mfileRepo domain.MediaFileRepository
}
@@ -32,6 +38,15 @@ type PlaylistInfo struct {
Owner string
}
func (p *playlists) Create(name string, ids []string) error {
pid, err := p.itunes.CreatePlaylist(name, ids)
if err != nil {
return err
}
beego.Info(fmt.Sprintf("Created playlist '%s' with id '%s'", name, pid))
return nil
}
func (p *playlists) Get(id string) (*PlaylistInfo, error) {
pl, err := p.plsRepo.Get(id)
if err != nil {