2022-09-19 15:54:37 +08:00
|
|
|
package annotationsimpl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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"
|
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 {
|
|
|
|
store store
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:04:01 +08:00
|
|
|
func ProvideService(db db.DB, cfg *setting.Cfg, tagService tag.Service) *RepositoryImpl {
|
2022-09-19 15:54:37 +08:00
|
|
|
return &RepositoryImpl{
|
2022-09-22 20:27:48 +08:00
|
|
|
store: &xormRepositoryImpl{
|
2022-09-23 18:04:41 +08:00
|
|
|
cfg: cfg,
|
|
|
|
db: db,
|
|
|
|
log: log.New("annotations"),
|
|
|
|
tagService: tagService,
|
|
|
|
maximumTagsLength: cfg.AnnotationMaximumTagsLength,
|
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) {
|
|
|
|
return r.store.Get(ctx, query)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|