Commit ee400df9 by nikita-graf

remove dashboard from playlist when its destroyed

parent be1fb131
...@@ -12,12 +12,12 @@ var ( ...@@ -12,12 +12,12 @@ var (
// Playlist model // Playlist model
type Playlist struct { type Playlist struct {
Id int64 `json:"id"` Id int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Type string `json:"type"` Type string `json:"type"`
Timespan string `json:"timespan"` Timespan string `json:"timespan"`
Data []int `json:"data"` Data []int64 `json:"data"`
OrgId int64 `json:"-"` OrgId int64 `json:"-"`
} }
type PlaylistDashboard struct { type PlaylistDashboard struct {
...@@ -49,7 +49,7 @@ type UpdatePlaylistQuery struct { ...@@ -49,7 +49,7 @@ type UpdatePlaylistQuery struct {
Title string Title string
Type string Type string
Timespan string Timespan string
Data []int Data []int64
Result *Playlist Result *Playlist
} }
...@@ -58,7 +58,7 @@ type CreatePlaylistQuery struct { ...@@ -58,7 +58,7 @@ type CreatePlaylistQuery struct {
Title string Title string
Type string Type string
Timespan string Timespan string
Data []int Data []int64
OrgId int64 OrgId int64
Result *Playlist Result *Playlist
......
...@@ -220,6 +220,26 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error { ...@@ -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 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