mirror of https://github.com/grafana/grafana
parent
b25bf363b3
commit
e02e60171e
@ -0,0 +1,17 @@ |
|||||||
|
package models |
||||||
|
|
||||||
|
type Favorite struct { |
||||||
|
Id int64 |
||||||
|
UserId int64 |
||||||
|
DashboardId int64 |
||||||
|
} |
||||||
|
|
||||||
|
type AddAsFavoriteCommand struct { |
||||||
|
UserId int64 |
||||||
|
DashboardId int64 |
||||||
|
} |
||||||
|
|
||||||
|
type RemoveAsFavoriteCommand struct { |
||||||
|
UserId int64 |
||||||
|
DashboardId int64 |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
package sqlstore |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/go-xorm/xorm" |
||||||
|
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/bus" |
||||||
|
m "github.com/torkelo/grafana-pro/pkg/models" |
||||||
|
) |
||||||
|
|
||||||
|
func init() { |
||||||
|
bus.AddHandler("sql", AddAsFavorite) |
||||||
|
bus.AddHandler("sql", RemoveAsFavorite) |
||||||
|
} |
||||||
|
|
||||||
|
func AddAsFavorite(cmd *m.AddAsFavoriteCommand) error { |
||||||
|
return inTransaction(func(sess *xorm.Session) error { |
||||||
|
|
||||||
|
entity := m.Favorite{ |
||||||
|
UserId: cmd.UserId, |
||||||
|
DashboardId: cmd.DashboardId, |
||||||
|
} |
||||||
|
|
||||||
|
_, err := sess.Insert(&entity) |
||||||
|
return err |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func RemoveAsFavorite(cmd *m.RemoveAsFavoriteCommand) error { |
||||||
|
return inTransaction(func(sess *xorm.Session) error { |
||||||
|
var rawSql = "DELETE FROM favorite WHERE user_id=? and dashboard_id=?" |
||||||
|
_, err := sess.Exec(rawSql, cmd.UserId, cmd.DashboardId) |
||||||
|
return err |
||||||
|
}) |
||||||
|
} |
||||||
Loading…
Reference in new issue