mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
* Query history: Add delete and refactor * Update docs/sources/http_api/query_history.md Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package queryhistory
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, routeRegister routing.RouteRegister) *QueryHistoryService {
|
|
s := &QueryHistoryService{
|
|
SQLStore: sqlStore,
|
|
Cfg: cfg,
|
|
RouteRegister: routeRegister,
|
|
log: log.New("query-history"),
|
|
}
|
|
|
|
// Register routes only when query history is enabled
|
|
if s.Cfg.QueryHistoryEnabled {
|
|
s.registerAPIEndpoints()
|
|
}
|
|
|
|
return s
|
|
}
|
|
|
|
type Service interface {
|
|
CreateQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, cmd CreateQueryInQueryHistoryCommand) (QueryHistoryDTO, error)
|
|
DeleteQueryFromQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (int64, error)
|
|
}
|
|
|
|
type QueryHistoryService struct {
|
|
SQLStore *sqlstore.SQLStore
|
|
Cfg *setting.Cfg
|
|
RouteRegister routing.RouteRegister
|
|
log log.Logger
|
|
}
|
|
|
|
func (s QueryHistoryService) CreateQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, cmd CreateQueryInQueryHistoryCommand) (QueryHistoryDTO, error) {
|
|
return s.createQuery(ctx, user, cmd)
|
|
}
|
|
|
|
func (s QueryHistoryService) DeleteQueryFromQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (int64, error) {
|
|
return s.deleteQuery(ctx, user, UID)
|
|
}
|