2022-01-28 10:55:09 -06:00
|
|
|
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 {
|
2022-02-04 09:14:36 -06:00
|
|
|
CreateQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, cmd CreateQueryInQueryHistoryCommand) (QueryHistoryDTO, error)
|
|
|
|
DeleteQueryFromQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (int64, error)
|
2022-02-15 08:43:17 -06:00
|
|
|
PatchQueryCommentInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string, cmd PatchQueryCommentInQueryHistoryCommand) (QueryHistoryDTO, error)
|
2022-02-23 10:03:04 -06:00
|
|
|
StarQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (QueryHistoryDTO, error)
|
|
|
|
UnstarQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (QueryHistoryDTO, error)
|
2022-01-28 10:55:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryHistoryService struct {
|
|
|
|
SQLStore *sqlstore.SQLStore
|
|
|
|
Cfg *setting.Cfg
|
|
|
|
RouteRegister routing.RouteRegister
|
|
|
|
log log.Logger
|
|
|
|
}
|
|
|
|
|
2022-02-04 09:14:36 -06:00
|
|
|
func (s QueryHistoryService) CreateQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, cmd CreateQueryInQueryHistoryCommand) (QueryHistoryDTO, error) {
|
2022-01-28 10:55:09 -06:00
|
|
|
return s.createQuery(ctx, user, cmd)
|
|
|
|
}
|
2022-02-04 09:14:36 -06:00
|
|
|
|
|
|
|
func (s QueryHistoryService) DeleteQueryFromQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (int64, error) {
|
|
|
|
return s.deleteQuery(ctx, user, UID)
|
|
|
|
}
|
2022-02-15 08:43:17 -06:00
|
|
|
|
|
|
|
func (s QueryHistoryService) PatchQueryCommentInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string, cmd PatchQueryCommentInQueryHistoryCommand) (QueryHistoryDTO, error) {
|
|
|
|
return s.patchQueryComment(ctx, user, UID, cmd)
|
|
|
|
}
|
2022-02-23 10:03:04 -06:00
|
|
|
|
|
|
|
func (s QueryHistoryService) StarQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (QueryHistoryDTO, error) {
|
|
|
|
return s.starQuery(ctx, user, UID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s QueryHistoryService) UnstarQueryInQueryHistory(ctx context.Context, user *models.SignedInUser, UID string) (QueryHistoryDTO, error) {
|
|
|
|
return s.unstarQuery(ctx, user, UID)
|
|
|
|
}
|