update return type of list to use pointer

This commit is contained in:
Vistaar Juneja 2023-08-10 16:52:39 +01:00
parent 01fffd56a3
commit c1ebb1837a
9 changed files with 19 additions and 20 deletions

View File

@ -20,7 +20,7 @@ func (c *Controller) List(
spaceRef string, spaceRef string,
pipelineUID string, pipelineUID string,
pagination types.Pagination, pagination types.Pagination,
) ([]types.Execution, int64, error) { ) ([]*types.Execution, int64, error) {
space, err := c.spaceStore.FindByRef(ctx, spaceRef) space, err := c.spaceStore.FindByRef(ctx, spaceRef)
if err != nil { if err != nil {
return nil, 0, fmt.Errorf("failed to find parent space: %w", err) return nil, 0, fmt.Errorf("failed to find parent space: %w", err)
@ -36,7 +36,7 @@ func (c *Controller) List(
} }
var count int64 var count int64
var executions []types.Execution var executions []*types.Execution
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) {
var dbErr error var dbErr error

View File

@ -20,7 +20,7 @@ func (c *Controller) ListPipelines(
session *auth.Session, session *auth.Session,
spaceRef string, spaceRef string,
pagination types.Pagination, pagination types.Pagination,
) ([]types.Pipeline, int64, error) { ) ([]*types.Pipeline, int64, error) {
space, err := c.spaceStore.FindByRef(ctx, spaceRef) space, err := c.spaceStore.FindByRef(ctx, spaceRef)
if err != nil { if err != nil {
return nil, 0, fmt.Errorf("failed to find parent space: %w", err) return nil, 0, fmt.Errorf("failed to find parent space: %w", err)
@ -32,7 +32,7 @@ func (c *Controller) ListPipelines(
} }
var count int64 var count int64
var pipelines []types.Pipeline var pipelines []*types.Pipeline
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) {
count, err = c.pipelineStore.Count(ctx, space.ID, pagination) count, err = c.pipelineStore.Count(ctx, space.ID, pagination)

View File

@ -20,7 +20,7 @@ func (c *Controller) ListSecrets(
session *auth.Session, session *auth.Session,
spaceRef string, spaceRef string,
pagination types.Pagination, pagination types.Pagination,
) ([]types.Secret, int64, error) { ) ([]*types.Secret, int64, error) {
space, err := c.spaceStore.FindByRef(ctx, spaceRef) space, err := c.spaceStore.FindByRef(ctx, spaceRef)
if err != nil { if err != nil {
return nil, 0, fmt.Errorf("failed to find parent space: %w", err) return nil, 0, fmt.Errorf("failed to find parent space: %w", err)
@ -32,7 +32,7 @@ func (c *Controller) ListSecrets(
} }
var count int64 var count int64
var secrets []types.Secret var secrets []*types.Secret
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) {
count, err = c.secretStore.Count(ctx, space.ID, pagination) count, err = c.secretStore.Count(ctx, space.ID, pagination)

View File

@ -453,7 +453,7 @@ type (
Update(ctx context.Context, pipeline *types.Pipeline) error Update(ctx context.Context, pipeline *types.Pipeline) error
// List lists the pipelines present in a parent space ID in the datastore. // 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 updates the pipeline using the optimistic locking mechanism.
UpdateOptLock(ctx context.Context, pipeline *types.Pipeline, UpdateOptLock(ctx context.Context, pipeline *types.Pipeline,
@ -499,7 +499,7 @@ type (
DeleteByUID(ctx context.Context, spaceID int64, uid string) error DeleteByUID(ctx context.Context, spaceID int64, uid string) error
// List lists the secrets in a given space // 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 { ExecutionStore interface {
@ -517,7 +517,7 @@ type (
mutateFn func(execution *types.Execution) error) (*types.Execution, error) mutateFn func(execution *types.Execution) error) (*types.Execution, error)
// List lists the executions for a given pipeline ID // 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 deletes an execution given a pipeline ID and an execution number
Delete(ctx context.Context, pipelineID int64, num int64) error Delete(ctx context.Context, pipelineID int64, num int64) error

View File

@ -249,7 +249,7 @@ func (s *executionStore) List(
ctx context.Context, ctx context.Context,
pipelineID int64, pipelineID int64,
pagination types.Pagination, pagination types.Pagination,
) ([]types.Execution, error) { ) ([]*types.Execution, error) {
stmt := database.Builder. stmt := database.Builder.
Select(executionColumns). Select(executionColumns).
From("executions"). From("executions").
@ -265,7 +265,7 @@ func (s *executionStore) List(
db := dbtx.GetAccessor(ctx, s.db) db := dbtx.GetAccessor(ctx, s.db)
dst := []types.Execution{} dst := []*types.Execution{}
if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { if err = db.SelectContext(ctx, &dst, sql, args...); err != nil {
return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query")
} }

View File

@ -173,7 +173,7 @@ func (s *pipelineStore) List(
ctx context.Context, ctx context.Context,
parentID int64, parentID int64,
pagination types.Pagination, pagination types.Pagination,
) ([]types.Pipeline, error) { ) ([]*types.Pipeline, error) {
stmt := database.Builder. stmt := database.Builder.
Select(pipelineColumns). Select(pipelineColumns).
From("pipelines"). From("pipelines").
@ -193,7 +193,7 @@ func (s *pipelineStore) List(
db := dbtx.GetAccessor(ctx, s.db) db := dbtx.GetAccessor(ctx, s.db)
dst := []types.Pipeline{} dst := []*types.Pipeline{}
if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { if err = db.SelectContext(ctx, &dst, sql, args...); err != nil {
return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query")
} }

View File

@ -152,7 +152,8 @@ func (s *secretStore) Update(ctx context.Context, secret *types.Secret) error {
// UpdateOptLock updates the pipeline using the optimistic locking mechanism. // UpdateOptLock updates the pipeline using the optimistic locking mechanism.
func (s *secretStore) UpdateOptLock(ctx context.Context, func (s *secretStore) UpdateOptLock(ctx context.Context,
secret *types.Secret, secret *types.Secret,
mutateFn func(secret *types.Secret) error) (*types.Secret, error) { mutateFn func(secret *types.Secret) error,
) (*types.Secret, error) {
for { for {
dup := *secret dup := *secret
@ -177,7 +178,7 @@ func (s *secretStore) UpdateOptLock(ctx context.Context,
} }
// List lists all the secrets present in a space. // 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. stmt := database.Builder.
Select(secretColumns). Select(secretColumns).
From("secrets"). From("secrets").
@ -197,7 +198,7 @@ func (s *secretStore) List(ctx context.Context, parentID int64, pagination types
db := dbtx.GetAccessor(ctx, s.db) db := dbtx.GetAccessor(ctx, s.db)
dst := []types.Secret{} dst := []*types.Secret{}
if err = db.SelectContext(ctx, &dst, sql, args...); err != nil { if err = db.SelectContext(ctx, &dst, sql, args...); err != nil {
return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query") return nil, database.ProcessSQLErrorf(err, "Failed executing custom list query")
} }

View File

@ -8,10 +8,9 @@ import (
context "context" context "context"
reflect "reflect" reflect "reflect"
gomock "github.com/golang/mock/gomock"
user "github.com/harness/gitness/internal/api/controller/user" user "github.com/harness/gitness/internal/api/controller/user"
types "github.com/harness/gitness/types" types "github.com/harness/gitness/types"
gomock "github.com/golang/mock/gomock"
) )
// MockClient is a mock of Client interface. // MockClient is a mock of Client interface.

View File

@ -8,10 +8,9 @@ import (
context "context" context "context"
reflect "reflect" reflect "reflect"
gomock "github.com/golang/mock/gomock"
types "github.com/harness/gitness/types" types "github.com/harness/gitness/types"
enum "github.com/harness/gitness/types/enum" enum "github.com/harness/gitness/types/enum"
gomock "github.com/golang/mock/gomock"
) )
// MockPrincipalStore is a mock of PrincipalStore interface. // MockPrincipalStore is a mock of PrincipalStore interface.