Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 2b2bdf5

Browse files
author
Noah Hanjun Lee
authored
Migrate the logic of converting errors into the Store package. (#190)
* Remove unused methods of interface. * Migrate handling errors into the store package
1 parent 3785dc1 commit 2b2bdf5

File tree

8 files changed

+40
-61
lines changed

8 files changed

+40
-61
lines changed

internal/interactor/license.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ func (i *Interactor) GetLicense(ctx context.Context) (*vo.License, error) {
2323
)
2424

2525
if memberCnt, err = i.Store.CountUsers(ctx); err != nil {
26-
return nil, e.NewError(
27-
e.ErrorCodeInternalError,
28-
err,
29-
)
26+
return nil, err
3027
}
3128

3229
if deploymentCnt, err = i.Store.CountDeployments(ctx); err != nil {
33-
return nil, e.NewError(
34-
e.ErrorCodeInternalError,
35-
err,
36-
)
30+
return nil, err
3731
}
3832

3933
if i.licenseKey == "" {

internal/pkg/store/deployment.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ import (
1313
)
1414

1515
func (s *Store) CountDeployments(ctx context.Context) (int, error) {
16-
return s.c.Deployment.
16+
cnt, err := s.c.Deployment.
1717
Query().
1818
Count(ctx)
19+
if err != nil {
20+
return 0, e.NewError(
21+
e.ErrorCodeInternalError,
22+
err,
23+
)
24+
}
25+
26+
return cnt, nil
1927
}
2028

2129
func (s *Store) SearchDeployments(ctx context.Context, u *ent.User, ss []deployment.Status, owned bool, from time.Time, to time.Time, page, perPage int) ([]*ent.Deployment, error) {

internal/pkg/store/user.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,23 @@ import (
55

66
"github.com/gitploy-io/gitploy/ent"
77
"github.com/gitploy-io/gitploy/ent/user"
8+
"github.com/gitploy-io/gitploy/pkg/e"
89
)
910

11+
func (s *Store) CountUsers(ctx context.Context) (int, error) {
12+
cnt, err := s.c.User.
13+
Query().
14+
Count(ctx)
15+
if err != nil {
16+
return 0, e.NewError(
17+
e.ErrorCodeInternalError,
18+
err,
19+
)
20+
}
21+
22+
return cnt, nil
23+
}
24+
1025
func (s *Store) ListUsers(ctx context.Context, login string, page, perPage int) ([]*ent.User, error) {
1126
return s.c.User.
1227
Query().
@@ -54,12 +69,6 @@ func (s *Store) FindUserByLogin(ctx context.Context, login string) (*ent.User, e
5469
Only(ctx)
5570
}
5671

57-
func (s *Store) CountUsers(ctx context.Context) (int, error) {
58-
return s.c.User.
59-
Query().
60-
Count(ctx)
61-
}
62-
6372
func (s *Store) CreateUser(ctx context.Context, u *ent.User) (*ent.User, error) {
6473
return s.c.User.Create().
6574
SetID(u.ID).

internal/server/api/v1/repos/interface.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type (
2727
FindDeploymentByID(ctx context.Context, id int) (*ent.Deployment, error)
2828
FindDeploymentOfRepoByNumber(ctx context.Context, r *ent.Repo, number int) (*ent.Deployment, error)
2929
FindPrevSuccessDeployment(ctx context.Context, d *ent.Deployment) (*ent.Deployment, error)
30-
GetNextDeploymentNumberOfRepo(ctx context.Context, r *ent.Repo) (int, error)
3130
IsApproved(ctx context.Context, d *ent.Deployment) bool
3231
Deploy(ctx context.Context, u *ent.User, re *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error)
3332
CreateRemoteDeployment(ctx context.Context, u *ent.User, re *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error)

internal/server/api/v1/repos/mock/interactor.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/server/hooks/mock/interactor.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/server/slack/interface.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type (
2929

3030
ListDeploymentsOfRepo(ctx context.Context, r *ent.Repo, env string, status string, page, perPage int) ([]*ent.Deployment, error)
3131
FindDeploymentByID(ctx context.Context, id int) (*ent.Deployment, error)
32-
GetNextDeploymentNumberOfRepo(ctx context.Context, r *ent.Repo) (int, error)
3332
Deploy(ctx context.Context, u *ent.User, re *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error)
3433
GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*vo.Config, error)
3534

internal/server/slack/mock/interactor.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)