Commit f5eac2e9 by bergquist

dashboards as cfg: expose dashboard service as interface

parent 16f072b3
......@@ -142,7 +142,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
UserId: c.UserId,
}
dashboard, err := dashboards.SaveDashboard(dashItem)
dashboard, err := dashboards.GetRepository().SaveDashboard(dashItem)
if err == m.ErrDashboardTitleEmpty {
return ApiError(400, m.ErrDashboardTitleEmpty.Error(), nil)
......
package dashboards
import (
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"time"
)
type Repository interface {
SaveDashboard(*SaveDashboardItem) error
SaveDashboard(*SaveDashboardItem) (*models.Dashboard, error)
}
var repositoryInstance Repository
func GetRepository() Repository {
return repositoryInstance
}
func SetRepository(rep Repository) {
repositoryInstance = rep
}
type SaveDashboardItem struct {
......@@ -22,7 +33,9 @@ type SaveDashboardItem struct {
Dashboard *models.Dashboard
}
func SaveDashboard(json *SaveDashboardItem) (*models.Dashboard, error) {
type dashboardRepository struct{}
func (dr *dashboardRepository) SaveDashboard(json *SaveDashboardItem) (*models.Dashboard, error) {
dashboard := json.Dashboard
if dashboard.Title == "" {
......
......@@ -3,12 +3,13 @@ package dashboards
import (
"context"
"fmt"
"github.com/grafana/grafana/pkg/services/dashboards"
"os"
"path/filepath"
"strings"
"time"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
......@@ -21,6 +22,7 @@ type fileReader struct {
Path string
log log.Logger
dashboardCache *dashboardCache
dashboardRepo dashboards.Repository
}
func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) {
......@@ -37,6 +39,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
Cfg: cfg,
Path: path,
log: log,
dashboardRepo: dashboards.GetRepository(),
dashboardCache: newDashboardCache(),
}, nil
}
......@@ -96,7 +99,7 @@ func (fr *fileReader) walkFolder() error {
if err == models.ErrDashboardNotFound {
fr.log.Debug("saving new dashboard", "file", path)
_, err = dashboards.SaveDashboard(dash)
_, err = fr.dashboardRepo.SaveDashboard(dash)
return err
}
......@@ -110,7 +113,7 @@ func (fr *fileReader) walkFolder() error {
}
fr.log.Debug("no dashboard in cache. loading dashboard from disk into database.", "file", path)
_, err = dashboards.SaveDashboard(dash)
_, err = fr.dashboardRepo.SaveDashboard(dash)
return err
})
}
......
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