backend/dashboardsnapshot service: move models (#50898)
* backend/dashboard snapshots: refactor leftover models and mocks * Move all dashboard snapshot-related models into the dashboardsnapshotservice package * Remove leftover dashboard-related mocks from the mockstore
This commit is contained in:
@@ -28,7 +28,7 @@ func ProvideStore(db db.DB) *DashboardSnapshotStore {
|
||||
// DeleteExpiredSnapshots removes snapshots with old expiry dates.
|
||||
// SnapShotRemoveExpired is deprecated and should be removed in the future.
|
||||
// Snapshot expiry is decided by the user when they share the snapshot.
|
||||
func (d *DashboardSnapshotStore) DeleteExpiredSnapshots(ctx context.Context, cmd *models.DeleteExpiredSnapshotsCommand) error {
|
||||
func (d *DashboardSnapshotStore) DeleteExpiredSnapshots(ctx context.Context, cmd *dashboardsnapshots.DeleteExpiredSnapshotsCommand) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
if !setting.SnapShotRemoveExpired {
|
||||
d.log.Warn("[Deprecated] The snapshot_remove_expired setting is outdated. Please remove from your config.")
|
||||
@@ -46,15 +46,14 @@ func (d *DashboardSnapshotStore) DeleteExpiredSnapshots(ctx context.Context, cmd
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardSnapshotStore) CreateDashboardSnapshot(ctx context.Context, cmd *models.CreateDashboardSnapshotCommand) error {
|
||||
func (d *DashboardSnapshotStore) CreateDashboardSnapshot(ctx context.Context, cmd *dashboardsnapshots.CreateDashboardSnapshotCommand) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
// never
|
||||
var expires = time.Now().Add(time.Hour * 24 * 365 * 50)
|
||||
if cmd.Expires > 0 {
|
||||
expires = time.Now().Add(time.Second * time.Duration(cmd.Expires))
|
||||
}
|
||||
|
||||
snapshot := &models.DashboardSnapshot{
|
||||
snapshot := &dashboardsnapshots.DashboardSnapshot{
|
||||
Name: cmd.Name,
|
||||
Key: cmd.Key,
|
||||
DeleteKey: cmd.DeleteKey,
|
||||
@@ -76,7 +75,7 @@ func (d *DashboardSnapshotStore) CreateDashboardSnapshot(ctx context.Context, cm
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardSnapshotStore) DeleteDashboardSnapshot(ctx context.Context, cmd *models.DeleteDashboardSnapshotCommand) error {
|
||||
func (d *DashboardSnapshotStore) DeleteDashboardSnapshot(ctx context.Context, cmd *dashboardsnapshots.DeleteDashboardSnapshotCommand) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
var rawSQL = "DELETE FROM dashboard_snapshot WHERE delete_key=?"
|
||||
_, err := sess.Exec(rawSQL, cmd.DeleteKey)
|
||||
@@ -84,10 +83,10 @@ func (d *DashboardSnapshotStore) DeleteDashboardSnapshot(ctx context.Context, cm
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardSnapshotStore) GetDashboardSnapshot(ctx context.Context, query *models.GetDashboardSnapshotQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(dbSess *sqlstore.DBSession) error {
|
||||
snapshot := models.DashboardSnapshot{Key: query.Key, DeleteKey: query.DeleteKey}
|
||||
has, err := dbSess.Get(&snapshot)
|
||||
func (d *DashboardSnapshotStore) GetDashboardSnapshot(ctx context.Context, query *dashboardsnapshots.GetDashboardSnapshotQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
snapshot := dashboardsnapshots.DashboardSnapshot{Key: query.Key, DeleteKey: query.DeleteKey}
|
||||
has, err := sess.Get(&snapshot)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -102,9 +101,9 @@ func (d *DashboardSnapshotStore) GetDashboardSnapshot(ctx context.Context, query
|
||||
|
||||
// SearchDashboardSnapshots returns a list of all snapshots for admins
|
||||
// for other roles, it returns snapshots created by the user
|
||||
func (d *DashboardSnapshotStore) SearchDashboardSnapshots(ctx context.Context, query *models.GetDashboardSnapshotsQuery) error {
|
||||
func (d *DashboardSnapshotStore) SearchDashboardSnapshots(ctx context.Context, query *dashboardsnapshots.GetDashboardSnapshotsQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
var snapshots = make(models.DashboardSnapshotsList, 0)
|
||||
var snapshots = make(dashboardsnapshots.DashboardSnapshotsList, 0)
|
||||
if query.Limit > 0 {
|
||||
sess.Limit(query.Limit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user