Skip to content

Commit

Permalink
Add more queries for managing bundles and subscriptions (#5028)
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <[email protected]>
  • Loading branch information
rdimitrov authored Nov 22, 2024
1 parent 11a3d5c commit c6efd48
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/querier/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,61 @@ type BundleHandlers interface {
bundleNamespace, bundleName string,
) (*BundleSubscription, error)
SetCurrentVersion(ctx context.Context, projectID uuid.UUID, currentVersion string) error
UpsertBundle(ctx context.Context, namespace, name string) error
GetBundleID(ctx context.Context, namespace, name string) (uuid.UUID, error)
CreateSubscription(ctx context.Context, projectID, bundleID uuid.UUID, currentVersion string) (*BundleSubscription, error)
}

// CreateSubscription creates a subscription for a project and bundle
func (q *querierType) CreateSubscription(
ctx context.Context,
projectID, bundleID uuid.UUID,
currentVersion string,
) (*BundleSubscription, error) {
if q.querier == nil {
return nil, ErrQuerierMissing
}
ret, err := q.querier.CreateSubscription(ctx, db.CreateSubscriptionParams{
ProjectID: projectID,
BundleID: bundleID,
CurrentVersion: currentVersion,
})
if err != nil {
return nil, err
}
return &BundleSubscription{
ID: ret.ID,
ProjectID: ret.ProjectID,
BundleID: ret.BundleID,
CurrentVersion: ret.CurrentVersion,
}, nil
}

// GetBundleID gets the bundle ID
func (q *querierType) GetBundleID(ctx context.Context, namespace, name string) (uuid.UUID, error) {
if q.querier == nil {
return uuid.Nil, ErrQuerierMissing
}
ret, err := q.querier.GetBundle(ctx, db.GetBundleParams{
Namespace: namespace,
Name: name,
})
if err != nil {
return uuid.Nil, err
}
// Return the bundle ID
return ret.ID, nil
}

// UpsertBundle creates a bundle if it does not exist
func (q *querierType) UpsertBundle(ctx context.Context, namespace, name string) error {
if q.querier == nil {
return ErrQuerierMissing
}
return q.querier.UpsertBundle(ctx, db.UpsertBundleParams{
Namespace: namespace,
Name: name,
})
}

// SetCurrentVersion sets the current version of the bundle for a project
Expand Down

0 comments on commit c6efd48

Please sign in to comment.