mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-28 07:01:59 +08:00

* chore(dashboard): intial commit * chore(dashboard): bring all the code in module * chore(dashboard): remove lock unlock from ee codebase * chore(dashboard): go deps * chore(dashboard): fix lint * chore(dashboard): implement the store * chore(dashboard): add migration * chore(dashboard): fix lint * chore(dashboard): api and frontend changes * chore(dashboard): frontend changes for new dashboards * chore(dashboard): fix test cases * chore(dashboard): add lock unlock APIs * chore(dashboard): add lock unlock APIs * chore(dashboard): move integrations controller out from module * chore(dashboard): move integrations controller out from module * chore(dashboard): move integrations controller out from module * chore(dashboard): rename migration file * chore(dashboard): surface errors for lock/unlock dashboard * chore(dashboard): some testing cleanups * chore(dashboard): fix postgres migrations --------- Co-authored-by: Vibhu Pandey <vibhupandey28@gmail.com>
100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package impldashboard
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
|
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type store struct {
|
|
sqlstore sqlstore.SQLStore
|
|
}
|
|
|
|
func NewStore(sqlstore sqlstore.SQLStore) dashboardtypes.Store {
|
|
return &store{sqlstore: sqlstore}
|
|
}
|
|
|
|
func (store *store) Create(ctx context.Context, storabledashboard *dashboardtypes.StorableDashboard) error {
|
|
_, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewInsert().
|
|
Model(storabledashboard).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.sqlstore.WrapAlreadyExistsErrf(err, errors.CodeAlreadyExists, "dashboard with id %s already exists", storabledashboard.ID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *store) Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*dashboardtypes.StorableDashboard, error) {
|
|
storableDashboard := new(dashboardtypes.StorableDashboard)
|
|
|
|
err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(storableDashboard).
|
|
Where("id = ?", id).
|
|
Where("org_id = ?", orgID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "dashboard with id %s doesn't exist", id)
|
|
}
|
|
|
|
return storableDashboard, nil
|
|
}
|
|
|
|
func (store *store) List(ctx context.Context, orgID valuer.UUID) ([]*dashboardtypes.StorableDashboard, error) {
|
|
storableDashboards := make([]*dashboardtypes.StorableDashboard, 0)
|
|
|
|
err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(&storableDashboards).
|
|
Where("org_id = ?", orgID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "no dashboards found in orgID %s", orgID)
|
|
}
|
|
|
|
return storableDashboards, nil
|
|
}
|
|
|
|
func (store *store) Update(ctx context.Context, orgID valuer.UUID, storableDashboard *dashboardtypes.StorableDashboard) error {
|
|
_, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewUpdate().
|
|
Model(storableDashboard).
|
|
WherePK().
|
|
Where("org_id = ?", orgID).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.sqlstore.WrapNotFoundErrf(err, errors.CodeAlreadyExists, "dashboard with id %s doesn't exist", storableDashboard.ID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *store) Delete(ctx context.Context, orgID valuer.UUID, id valuer.UUID) error {
|
|
_, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewDelete().
|
|
Model(new(dashboardtypes.StorableDashboard)).
|
|
Where("id = ?", id).
|
|
Where("org_id = ?", orgID).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "dashboard with id %s doesn't exist", id)
|
|
}
|
|
|
|
return nil
|
|
}
|