2022-09-19 15:54:37 +08:00
|
|
|
package annotationsimpl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-11-15 07:11:01 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/annotations/accesscontrol"
|
|
|
|
|
2022-10-19 21:02:15 +08:00
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
2022-09-19 15:54:37 +08:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
|
|
"github.com/grafana/grafana/pkg/services/annotations"
|
2023-04-06 16:16:15 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2022-09-21 20:04:01 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/tag"
|
2022-09-19 15:54:37 +08:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RepositoryImpl struct {
|
2023-11-15 07:11:01 +08:00
|
|
|
db db.DB
|
|
|
|
authZ *accesscontrol.AuthService
|
|
|
|
features featuremgmt.FeatureToggles
|
|
|
|
store store
|
2022-09-19 15:54:37 +08:00
|
|
|
}
|
|
|
|
|
2023-11-15 07:11:01 +08:00
|
|
|
func ProvideService(
|
|
|
|
db db.DB,
|
|
|
|
cfg *setting.Cfg,
|
|
|
|
features featuremgmt.FeatureToggles,
|
|
|
|
tagService tag.Service,
|
|
|
|
) *RepositoryImpl {
|
|
|
|
l := log.New("annotations")
|
|
|
|
|
2022-09-19 15:54:37 +08:00
|
|
|
return &RepositoryImpl{
|
2023-11-15 07:11:01 +08:00
|
|
|
db: db,
|
|
|
|
features: features,
|
|
|
|
authZ: accesscontrol.NewAuthService(db, features),
|
|
|
|
store: NewXormStore(cfg, l, db, tagService),
|
2022-09-19 15:54:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepositoryImpl) Save(ctx context.Context, item *annotations.Item) error {
|
|
|
|
return r.store.Add(ctx, item)
|
|
|
|
}
|
|
|
|
|
2022-11-04 23:39:26 +08:00
|
|
|
// SaveMany inserts multiple annotations at once.
|
|
|
|
// It does not return IDs associated with created annotations. If you need this functionality, use the single-item Save instead.
|
|
|
|
func (r *RepositoryImpl) SaveMany(ctx context.Context, items []annotations.Item) error {
|
|
|
|
return r.store.AddMany(ctx, items)
|
|
|
|
}
|
|
|
|
|
2022-09-19 15:54:37 +08:00
|
|
|
func (r *RepositoryImpl) Update(ctx context.Context, item *annotations.Item) error {
|
|
|
|
return r.store.Update(ctx, item)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepositoryImpl) Find(ctx context.Context, query *annotations.ItemQuery) ([]*annotations.ItemDTO, error) {
|
2023-11-15 07:11:01 +08:00
|
|
|
resources, err := r.authZ.Authorize(ctx, query.OrgID, query.SignedInUser)
|
|
|
|
if err != nil {
|
|
|
|
return make([]*annotations.ItemDTO, 0), err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.store.Get(ctx, query, resources)
|
2022-09-19 15:54:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepositoryImpl) Delete(ctx context.Context, params *annotations.DeleteParams) error {
|
|
|
|
return r.store.Delete(ctx, params)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepositoryImpl) FindTags(ctx context.Context, query *annotations.TagsQuery) (annotations.FindTagsResult, error) {
|
|
|
|
return r.store.GetTags(ctx, query)
|
|
|
|
}
|