2020-07-30 04:59:12 -05:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2021-11-03 05:31:56 -05:00
|
|
|
"context"
|
2020-07-30 04:59:12 -05:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
2022-02-23 04:12:37 -06:00
|
|
|
type OrgStore interface {
|
|
|
|
GetOrgById(context.Context, *models.GetOrgByIdQuery) error
|
|
|
|
}
|
|
|
|
|
2022-04-08 06:56:38 -05:00
|
|
|
type DashboardStore interface {
|
|
|
|
GetDashboard(context.Context, *models.GetDashboardQuery) error
|
|
|
|
}
|
|
|
|
|
2022-02-23 04:12:37 -06:00
|
|
|
func CheckOrgExists(ctx context.Context, store OrgStore, orgID int64) error {
|
2020-07-30 04:59:12 -05:00
|
|
|
query := models.GetOrgByIdQuery{Id: orgID}
|
2022-02-23 04:12:37 -06:00
|
|
|
if err := store.GetOrgById(ctx, &query); err != nil {
|
2020-07-30 04:59:12 -05:00
|
|
|
if errors.Is(err, models.ErrOrgNotFound) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return fmt.Errorf("failed to check whether org. with the given ID exists: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|