From c1ebb1837a202f237315b1aa7927678511844d6c Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Thu, 10 Aug 2023 16:52:39 +0100 Subject: [PATCH] update return type of list to use pointer --- internal/api/controller/execution/list.go | 4 ++-- internal/api/controller/space/list_pipelines.go | 4 ++-- internal/api/controller/space/list_secrets.go | 4 ++-- internal/store/database.go | 6 +++--- internal/store/database/execution.go | 4 ++-- internal/store/database/pipeline.go | 4 ++-- internal/store/database/secret.go | 7 ++++--- mocks/mock_client.go | 3 +-- mocks/mock_store.go | 3 +-- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/internal/api/controller/execution/list.go b/internal/api/controller/execution/list.go index 2d2285521..e0a6d6587 100644 --- a/internal/api/controller/execution/list.go +++ b/internal/api/controller/execution/list.go @@ -20,7 +20,7 @@ func (c *Controller) List( spaceRef string, pipelineUID string, pagination types.Pagination, -) ([]types.Execution, int64, error) { +) ([]*types.Execution, int64, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, 0, fmt.Errorf("failed to find parent space: %w", err) @@ -36,7 +36,7 @@ func (c *Controller) List( } var count int64 - var executions []types.Execution + var executions []*types.Execution err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { var dbErr error diff --git a/internal/api/controller/space/list_pipelines.go b/internal/api/controller/space/list_pipelines.go index 276106671..e80bc3586 100644 --- a/internal/api/controller/space/list_pipelines.go +++ b/internal/api/controller/space/list_pipelines.go @@ -20,7 +20,7 @@ func (c *Controller) ListPipelines( session *auth.Session, spaceRef string, pagination types.Pagination, -) ([]types.Pipeline, int64, error) { +) ([]*types.Pipeline, int64, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, 0, fmt.Errorf("failed to find parent space: %w", err) @@ -32,7 +32,7 @@ func (c *Controller) ListPipelines( } var count int64 - var pipelines []types.Pipeline + var pipelines []*types.Pipeline err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { count, err = c.pipelineStore.Count(ctx, space.ID, pagination) diff --git a/internal/api/controller/space/list_secrets.go b/internal/api/controller/space/list_secrets.go index 63db20f8e..7db2fda4f 100644 --- a/internal/api/controller/space/list_secrets.go +++ b/internal/api/controller/space/list_secrets.go @@ -20,7 +20,7 @@ func (c *Controller) ListSecrets( session *auth.Session, spaceRef string, pagination types.Pagination, -) ([]types.Secret, int64, error) { +) ([]*types.Secret, int64, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, 0, fmt.Errorf("failed to find parent space: %w", err) @@ -32,7 +32,7 @@ func (c *Controller) ListSecrets( } var count int64 - var secrets []types.Secret + var secrets []*types.Secret err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { count, err = c.secretStore.Count(ctx, space.ID, pagination) diff --git a/internal/store/database.go b/internal/store/database.go index 3d4c6bd24..28d9037d7 100644 --- a/internal/store/database.go +++ b/internal/store/database.go @@ -453,7 +453,7 @@ type ( Update(ctx context.Context, pipeline *types.Pipeline) error // List lists the pipelines present in a parent space ID in the datastore. - List(ctx context.Context, spaceID int64, pagination types.Pagination) ([]types.Pipeline, error) + List(ctx context.Context, spaceID int64, pagination types.Pagination) ([]*types.Pipeline, error) // UpdateOptLock updates the pipeline using the optimistic locking mechanism. UpdateOptLock(ctx context.Context, pipeline *types.Pipeline, @@ -499,7 +499,7 @@ type ( DeleteByUID(ctx context.Context, spaceID int64, uid string) error // List lists the secrets in a given space - List(ctx context.Context, spaceID int64, filter types.Pagination) ([]types.Secret, error) + List(ctx context.Context, spaceID int64, filter types.Pagination) ([]*types.Secret, error) } ExecutionStore interface { @@ -517,7 +517,7 @@ type ( mutateFn func(execution *types.Execution) error) (*types.Execution, error) // List lists the executions for a given pipeline ID - List(ctx context.Context, pipelineID int64, pagination types.Pagination) ([]types.Execution, error) + List(ctx context.Context, pipelineID int64, pagination types.Pagination) ([]*types.Execution, error) // Delete deletes an execution given a pipeline ID and an execution number Delete(ctx context.Context, pipelineID int64, num int64) error diff --git a/internal/store/database/execution.go b/internal/store/database/execution.go index 8edc51338..f78e5d6ce 100644 --- a/internal/store/database/execution.go +++ b/internal/store/database/execution.go @@ -249,7 +249,7 @@ func (s *executionStore) List( ctx context.Context, pipelineID int64, pagination types.Pagination, -) ([]types.Execution, error) { +) ([]*types.Execution, error) { stmt := database.Builder. Select(executionColumns). From("executions"). @@ -265,7 +265,7 @@ func (s *executionStore) List( db := dbtx.GetAccessor(ctx, s.db) - dst := []types.Execution{} + dst := []*types.Execution{} if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") } diff --git a/internal/store/database/pipeline.go b/internal/store/database/pipeline.go index 5b83426f8..d341302d6 100644 --- a/internal/store/database/pipeline.go +++ b/internal/store/database/pipeline.go @@ -173,7 +173,7 @@ func (s *pipelineStore) List( ctx context.Context, parentID int64, pagination types.Pagination, -) ([]types.Pipeline, error) { +) ([]*types.Pipeline, error) { stmt := database.Builder. Select(pipelineColumns). From("pipelines"). @@ -193,7 +193,7 @@ func (s *pipelineStore) List( db := dbtx.GetAccessor(ctx, s.db) - dst := []types.Pipeline{} + dst := []*types.Pipeline{} if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") } diff --git a/internal/store/database/secret.go b/internal/store/database/secret.go index 5761a468b..7f7e9386b 100644 --- a/internal/store/database/secret.go +++ b/internal/store/database/secret.go @@ -152,7 +152,8 @@ func (s *secretStore) Update(ctx context.Context, secret *types.Secret) error { // UpdateOptLock updates the pipeline using the optimistic locking mechanism. func (s *secretStore) UpdateOptLock(ctx context.Context, secret *types.Secret, - mutateFn func(secret *types.Secret) error) (*types.Secret, error) { + mutateFn func(secret *types.Secret) error, +) (*types.Secret, error) { for { dup := *secret @@ -177,7 +178,7 @@ func (s *secretStore) UpdateOptLock(ctx context.Context, } // List lists all the secrets present in a space. -func (s *secretStore) List(ctx context.Context, parentID int64, pagination types.Pagination) ([]types.Secret, error) { +func (s *secretStore) List(ctx context.Context, parentID int64, pagination types.Pagination) ([]*types.Secret, error) { stmt := database.Builder. Select(secretColumns). From("secrets"). @@ -197,7 +198,7 @@ func (s *secretStore) List(ctx context.Context, parentID int64, pagination types db := dbtx.GetAccessor(ctx, s.db) - dst := []types.Secret{} + dst := []*types.Secret{} if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") } diff --git a/mocks/mock_client.go b/mocks/mock_client.go index 3cb746055..b16a6490e 100644 --- a/mocks/mock_client.go +++ b/mocks/mock_client.go @@ -8,10 +8,9 @@ import ( context "context" reflect "reflect" + gomock "github.com/golang/mock/gomock" user "github.com/harness/gitness/internal/api/controller/user" types "github.com/harness/gitness/types" - - gomock "github.com/golang/mock/gomock" ) // MockClient is a mock of Client interface. diff --git a/mocks/mock_store.go b/mocks/mock_store.go index 9310f3729..0af0bbc34 100644 --- a/mocks/mock_store.go +++ b/mocks/mock_store.go @@ -8,10 +8,9 @@ import ( context "context" reflect "reflect" + gomock "github.com/golang/mock/gomock" types "github.com/harness/gitness/types" enum "github.com/harness/gitness/types/enum" - - gomock "github.com/golang/mock/gomock" ) // MockPrincipalStore is a mock of PrincipalStore interface.