deletePlaylist

This commit is contained in:
Deluan 2016-03-24 12:17:35 -04:00
parent 52850c6ef0
commit a27803a4d1
4 changed files with 30 additions and 0 deletions

View File

@ -67,6 +67,16 @@ func (c *PlaylistsController) Create() {
c.SendEmptyResponse()
}
func (c *PlaylistsController) Delete() {
id := c.RequiredParamString("id", "Required parameter id is missing")
err := c.pls.Delete(id)
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

View File

@ -42,6 +42,7 @@ func mapEndpoints() {
beego.NSRouter("/getPlaylists.view", &api.PlaylistsController{}, "*:GetAll"),
beego.NSRouter("/getPlaylist.view", &api.PlaylistsController{}, "*:Get"),
beego.NSRouter("/createPlaylist.view", &api.PlaylistsController{}, "*:Create"),
beego.NSRouter("/deletePlaylist.view", &api.PlaylistsController{}, "*:Delete"),
beego.NSRouter("/getUser.view", &api.UsersController{}, "*:GetUser"),
)

View File

@ -12,6 +12,7 @@ type Playlists interface {
GetAll() (domain.Playlists, error)
Get(id string) (*PlaylistInfo, error)
Create(name string, ids []string) error
Delete(id string) error
}
func NewPlaylists(itunes itunesbridge.ItunesControl, pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {
@ -47,6 +48,15 @@ func (p *playlists) Create(name string, ids []string) error {
return nil
}
func (p *playlists) Delete(id string) error {
err := p.itunes.DeletePlaylist(id)
if err != nil {
return err
}
beego.Info(fmt.Sprintf("Deleted playlist with id '%s'", id))
return nil
}
func (p *playlists) Get(id string) (*PlaylistInfo, error) {
pl, err := p.plsRepo.Get(id)
if err != nil {

View File

@ -14,6 +14,7 @@ type ItunesControl interface {
SetTrackRating(trackId string, rating int) error
SetAlbumRating(trackId string, rating int) error
CreatePlaylist(name string, ids []string) (string, error)
DeletePlaylist(id string) error
}
func NewItunesControl() ItunesControl {
@ -39,6 +40,14 @@ func (c *itunesControl) CreatePlaylist(name string, ids []string) (string, error
return strings.TrimSuffix(pid, "\n"), nil
}
func (c *itunesControl) DeletePlaylist(id string) error {
script := Script{
fmt.Sprintf(`set pls to the first item of (every playlist whose persistent ID is equal to "%s")`, id),
`delete pls`,
}
return script.Run()
}
func (c *itunesControl) MarkAsPlayed(trackId string, playDate time.Time) error {
script := Script{fmt.Sprintf(
`set theTrack to the first item of (every track whose persistent ID is equal to "%s")`, trackId),