Commit ee400df9 by nikita-graf

remove dashboard from playlist when its destroyed

parent be1fb131
......@@ -12,12 +12,12 @@ var (
// Playlist model
type Playlist struct {
Id int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Timespan string `json:"timespan"`
Data []int `json:"data"`
OrgId int64 `json:"-"`
Id int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Timespan string `json:"timespan"`
Data []int64 `json:"data"`
OrgId int64 `json:"-"`
}
type PlaylistDashboard struct {
......@@ -49,7 +49,7 @@ type UpdatePlaylistQuery struct {
Title string
Type string
Timespan string
Data []int
Data []int64
Result *Playlist
}
......@@ -58,7 +58,7 @@ type CreatePlaylistQuery struct {
Title string
Type string
Timespan string
Data []int
Data []int64
OrgId int64
Result *Playlist
......
......@@ -220,6 +220,26 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
}
}
var playlists = make(m.Playlists, 0)
err = sess.Where("data LIKE ?", fmt.Sprintf("%%%v%%", dashboard.Id)).Find(&playlists)
if err != nil {
return err
}
for _, playlist := range playlists {
filteredData := make([]int64, 0)
for _, plDashboardId := range playlist.Data {
if plDashboardId != dashboard.Id {
filteredData = append(filteredData, plDashboardId)
}
}
playlist.Data = filteredData
_, err = sess.Id(playlist.Id).Cols("data").Update(playlist)
if err != nil {
return err
}
}
return nil
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment