Esempio n. 1
0
func CreatePlaylist(query *m.CreatePlaylistQuery) error {
	var err error

	playlist := m.Playlist{
		Title:    query.Title,
		Interval: query.Interval,
		OrgId:    query.OrgId,
	}

	_, err = x.Insert(&playlist)

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

	playlistItems := make([]m.PlaylistItem, 0)
	for _, item := range query.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)

	query.Result = &playlist
	return err
}
Esempio n. 2
0
func CreatePlaylist(c *middleware.Context, query m.CreatePlaylistQuery) Response {
	query.OrgId = c.OrgId
	err := bus.Dispatch(&query)
	if err != nil {
		return ApiError(500, "Failed to create playlist", err)
	}

	return Json(200, query.Result)
}