Skip to content

Commit 9e4aa19

Browse files
committed
chore: modify params type
1 parent d62286b commit 9e4aa19

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

controller/branch_ctl.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ func (bct BranchController) ListBranches(ctx context.Context, w *api.JiaozifsRes
7575
}
7676

7777
listBranchParams := models.NewListBranchParams()
78-
listBranchParams.SetName(params.Prefix, models.PrefixMatch)
79-
listBranchParams.SetAfter(params.After)
78+
if params.Prefix != nil && len(*params.Prefix) > 0 {
79+
listBranchParams.SetName(*params.Prefix, models.PrefixMatch)
80+
}
81+
if params.After != nil && len(*params.After) > 0 {
82+
listBranchParams.SetAfter(*params.After)
83+
}
8084
pageAmount := utils.IntValue(params.Amount)
8185
if pageAmount > utils.DefaultMaxPerPage || pageAmount <= 0 {
8286
listBranchParams.SetAmount(utils.DefaultMaxPerPage)

controller/repository_ctl.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,21 @@ func (repositoryCtl RepositoryController) ListRepositoryOfAuthenticatedUser(ctx
6161
return
6262
}
6363

64-
listParams := models.NewListRepoParams()
65-
listParams.SetName(params.Prefix, models.PrefixMatch)
66-
listParams.SetAfter(params.After)
64+
listRepoParams := models.NewListRepoParams()
65+
if params.Prefix != nil && len(*params.Prefix) > 0 {
66+
listRepoParams.SetName(*params.Prefix, models.PrefixMatch)
67+
}
68+
if params.After != nil {
69+
listRepoParams.SetAfter(*params.After)
70+
}
6771
pageAmount := utils.IntValue(params.Amount)
6872
if pageAmount > utils.DefaultMaxPerPage || pageAmount <= 0 {
69-
listParams.SetAmount(utils.DefaultMaxPerPage)
73+
listRepoParams.SetAmount(utils.DefaultMaxPerPage)
7074
} else {
71-
listParams.SetAmount(pageAmount)
75+
listRepoParams.SetAmount(pageAmount)
7276
}
7377

74-
repositories, hasMore, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, listParams.
78+
repositories, hasMore, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, listRepoParams.
7579
SetOwnerID(operator.ID))
7680
if err != nil {
7781
w.Error(err)
@@ -120,17 +124,21 @@ func (repositoryCtl RepositoryController) ListRepository(ctx context.Context, w
120124
return
121125
}
122126

123-
listParams := models.NewListRepoParams().SetOwnerID(owner.ID)
124-
listParams.SetName(params.Prefix, models.PrefixMatch)
125-
listParams.SetAfter(params.After)
127+
listRepoParams := models.NewListRepoParams().SetOwnerID(owner.ID)
128+
if params.Prefix != nil && len(*params.Prefix) > 0 {
129+
listRepoParams.SetName(*params.Prefix, models.PrefixMatch)
130+
}
131+
if params.After != nil {
132+
listRepoParams.SetAfter(*params.After)
133+
}
126134
pageAmount := utils.IntValue(params.Amount)
127135
if pageAmount > utils.DefaultMaxPerPage || pageAmount <= 0 {
128-
listParams.SetAmount(utils.DefaultMaxPerPage)
136+
listRepoParams.SetAmount(utils.DefaultMaxPerPage)
129137
} else {
130-
listParams.SetAmount(pageAmount)
138+
listRepoParams.SetAmount(pageAmount)
131139
}
132140

133-
repositories, hasMore, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, listParams)
141+
repositories, hasMore, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, listRepoParams)
134142
if err != nil {
135143
w.Error(err)
136144
return

models/branch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ func (gup *ListBranchParams) SetRepositoryID(repositoryID uuid.UUID) *ListBranch
108108
return gup
109109
}
110110

111-
func (gup *ListBranchParams) SetName(name *string, match MatchMode) *ListBranchParams {
112-
gup.Name = name
111+
func (gup *ListBranchParams) SetName(name string, match MatchMode) *ListBranchParams {
112+
gup.Name = &name
113113
gup.NameMatch = match
114114
return gup
115115
}
116116

117-
func (gup *ListBranchParams) SetAfter(after *string) *ListBranchParams {
118-
gup.After = after
117+
func (gup *ListBranchParams) SetAfter(after string) *ListBranchParams {
118+
gup.After = &after
119119
return gup
120120
}
121121

models/branch_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/google/uuid"
1010
"github.com/jiaozifs/jiaozifs/models"
1111
"github.com/jiaozifs/jiaozifs/testhelper"
12-
"github.com/jiaozifs/jiaozifs/utils"
1312
"github.com/jiaozifs/jiaozifs/utils/hash"
1413
"github.com/stretchr/testify/require"
1514
)
@@ -70,31 +69,31 @@ func TestRefRepoInsert(t *testing.T) {
7069
require.True(t, cmp.Equal(secModel, sRef, dbTimeCmpOpt))
7170

7271
// ExactMatch
73-
list1, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(utils.String(secModel.Name), models.ExactMatch).SetAmount(1))
72+
list1, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(secModel.Name, models.ExactMatch).SetAmount(1))
7473
require.NoError(t, err)
7574
require.Len(t, list1, 1)
7675
require.True(t, hasMore)
7776

7877
// PrefixMatch
79-
list2, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(utils.String(secModel.Name[:3]), models.PrefixMatch).SetAmount(1))
78+
list2, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(secModel.Name[:3], models.PrefixMatch).SetAmount(1))
8079
require.NoError(t, err)
8180
require.Len(t, list2, 1)
8281
require.True(t, hasMore)
8382

8483
// SuffixMatch
85-
list3, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(utils.String(secModel.Name[3:]), models.SuffixMatch).SetAmount(1))
84+
list3, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(secModel.Name[3:], models.SuffixMatch).SetAmount(1))
8685
require.NoError(t, err)
8786
require.Len(t, list3, 1)
8887
require.True(t, hasMore)
8988

9089
// LikeMatch
91-
list4, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(utils.String(secModel.Name[2:4]), models.LikeMatch).SetAmount(1))
90+
list4, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetName(secModel.Name[2:4], models.LikeMatch).SetAmount(1))
9291
require.NoError(t, err)
9392
require.Len(t, list4, 1)
9493
require.True(t, hasMore)
9594

9695
// After
97-
list5, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetAfter(utils.String("feat/abcd/aaa")))
96+
list5, hasMore, err := repo.List(ctx, models.NewListBranchParams().SetRepositoryID(branch.RepositoryID).SetAfter("feat/abcd/aaa"))
9897
require.NoError(t, err)
9998
require.Len(t, list5, 1)
10099
require.False(t, hasMore)

models/repository.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func (lrp *ListRepoParams) SetOwnerID(ownerID uuid.UUID) *ListRepoParams {
7575
return lrp
7676
}
7777

78-
func (lrp *ListRepoParams) SetName(name *string, match MatchMode) *ListRepoParams {
79-
lrp.Name = name
78+
func (lrp *ListRepoParams) SetName(name string, match MatchMode) *ListRepoParams {
79+
lrp.Name = &name
8080
lrp.NameMatch = match
8181
return lrp
8282
}
@@ -86,8 +86,8 @@ func (lrp *ListRepoParams) SetCreatorID(creatorID uuid.UUID) *ListRepoParams {
8686
return lrp
8787
}
8888

89-
func (lrp *ListRepoParams) SetAfter(after *time.Time) *ListRepoParams {
90-
lrp.After = after
89+
func (lrp *ListRepoParams) SetAfter(after time.Time) *ListRepoParams {
90+
lrp.After = &after
9191
return lrp
9292
}
9393

models/repository_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/google/uuid"
1111
"github.com/jiaozifs/jiaozifs/models"
1212
"github.com/jiaozifs/jiaozifs/testhelper"
13-
"github.com/jiaozifs/jiaozifs/utils"
1413
"github.com/stretchr/testify/require"
1514
)
1615

@@ -54,32 +53,32 @@ func TestRepositoryRepo_Insert(t *testing.T) {
5453

5554
{
5655
//exact adabbeb
57-
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName(utils.String("adabbeb"), models.PrefixMatch))
56+
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName("adabbeb", models.PrefixMatch))
5857
require.NoError(t, err)
5958
require.Len(t, repos, 1)
6059
}
6160
{
6261
//prefix a
63-
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName(utils.String("a"), models.PrefixMatch))
62+
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName("a", models.PrefixMatch))
6463
require.NoError(t, err)
6564
require.Len(t, repos, 2)
6665
}
6766

6867
{
6968
//subfix b
70-
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName(utils.String("b"), models.SuffixMatch))
69+
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName("b", models.SuffixMatch))
7170
require.NoError(t, err)
7271
require.Len(t, repos, 2)
7372
}
7473
{
7574
//like ab
76-
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName(utils.String("ab"), models.LikeMatch))
75+
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName("ab", models.LikeMatch))
7776
require.NoError(t, err)
7877
require.Len(t, repos, 2)
7978
}
8079
{
8180
//like ab
82-
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName(utils.String("adabbeb"), models.LikeMatch))
81+
repos, _, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetName("adabbeb", models.LikeMatch))
8382
require.NoError(t, err)
8483
require.Len(t, repos, 1)
8584
}
@@ -106,7 +105,7 @@ func TestRepositoryRepo_Insert(t *testing.T) {
106105
}
107106
{
108107
//after
109-
repos, hasMore, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetAfter(utils.Time(time.Now())).SetAmount(1))
108+
repos, hasMore, err := repo.List(ctx, models.NewListRepoParams().SetCreatorID(secModel.CreatorID).SetAfter(time.Now()).SetAmount(1))
110109
require.NoError(t, err)
111110
require.True(t, hasMore)
112111
require.Len(t, repos, 1)

0 commit comments

Comments
 (0)