本文整理汇总了Golang中github.com/grafana/grafana/pkg/models.UpdatePlaylistCommand类的典型用法代码示例。如果您正苦于以下问题:Golang UpdatePlaylistCommand类的具体用法?Golang UpdatePlaylistCommand怎么用?Golang UpdatePlaylistCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UpdatePlaylistCommand类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdatePlaylist
func UpdatePlaylist(cmd *m.UpdatePlaylistCommand) error {
var err error
playlist := m.Playlist{
Id: cmd.Id,
OrgId: cmd.OrgId,
Name: cmd.Name,
Interval: cmd.Interval,
}
existingPlaylist := x.Where("id = ? AND org_id = ?", cmd.Id, cmd.OrgId).Find(m.Playlist{})
if existingPlaylist == nil {
return m.ErrPlaylistNotFound
}
cmd.Result = &m.PlaylistDTO{
Id: playlist.Id,
OrgId: playlist.OrgId,
Name: playlist.Name,
Interval: playlist.Interval,
}
_, err = x.Id(cmd.Id).Cols("id", "name", "interval").Update(&playlist)
if err != nil {
return err
}
rawSql := "DELETE FROM playlist_item WHERE playlist_id = ?"
_, err = x.Exec(rawSql, cmd.Id)
if err != nil {
return err
}
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)
return err
}
示例2: UpdatePlaylist
func UpdatePlaylist(c *middleware.Context, cmd m.UpdatePlaylistCommand) Response {
cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to save playlist", err)
}
playlistDTOs, err := LoadPlaylistItemDTOs(cmd.Id)
if err != nil {
return ApiError(500, "Failed to save playlist", err)
}
cmd.Result.Items = playlistDTOs
return Json(200, cmd.Result)
}