Example #1
0
func CreatePlaylist(cmd *m.CreatePlaylistCommand) error {
	var err error

	playlist := m.Playlist{
		Name:     cmd.Name,
		Interval: cmd.Interval,
		OrgId:    cmd.OrgId,
	}

	_, err = x.Insert(&playlist)

	fmt.Printf("%v", playlist.Id)

	playlistItems := make([]m.PlaylistItem, 0)
	for _, item := range cmd.Items {
		playlistItems = append(playlistItems, m.PlaylistItem{
			PlaylistId: playlist.Id,
			Type:       item.Type,
			Value:      item.Value,
			Order:      item.Order,
			Title:      item.Title,
		})
	}

	_, err = x.Insert(&playlistItems)

	cmd.Result = &playlist
	return err
}
Example #2
0
func CreatePlaylist(c *middleware.Context, cmd m.CreatePlaylistCommand) Response {
	cmd.OrgId = c.OrgId

	if err := bus.Dispatch(&cmd); err != nil {
		return ApiError(500, "Failed to create playlist", err)
	}

	return Json(200, cmd.Result)
}