Skip to content

Commit 46caf7c

Browse files
authored
refactor: use odpf project standards (#140)
* refactor: core, store and api packages * chore: clean unused code * test: fix tests * docs: add swagger api docs
1 parent 7a8f93b commit 46caf7c

53 files changed

Lines changed: 2015 additions & 2604 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/namespace/namespace.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66
)
77

8-
// Namespace model
98
type Namespace struct {
109
ID string
1110
Format string
@@ -15,20 +14,10 @@ type Namespace struct {
1514
UpdatedAt time.Time
1615
}
1716

18-
// NamespaceService namespace CRUD service
19-
type NamespaceService interface {
20-
Create(ctx context.Context, ns Namespace) (Namespace, error)
21-
Update(ctx context.Context, ns Namespace) (Namespace, error)
22-
List(ctx context.Context) ([]string, error)
23-
Get(ctx context.Context, name string) (Namespace, error)
24-
Delete(ctx context.Context, name string) error
25-
}
26-
27-
// NamespaceRepository for namespace
28-
type NamespaceRepository interface {
29-
CreateNamespace(context.Context, Namespace) (Namespace, error)
30-
UpdateNamespace(context.Context, Namespace) (Namespace, error)
31-
ListNamespaces(context.Context) ([]string, error)
32-
GetNamespace(context.Context, string) (Namespace, error)
33-
DeleteNamespace(context.Context, string) error
17+
type Repository interface {
18+
Create(context.Context, Namespace) (Namespace, error)
19+
Update(context.Context, Namespace) (Namespace, error)
20+
List(context.Context) ([]string, error)
21+
Get(context.Context, string) (Namespace, error)
22+
Delete(context.Context, string) error
3423
}

core/namespace/service.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,31 @@ import (
55
)
66

77
type Service struct {
8-
Repo NamespaceRepository
8+
repo Repository
9+
}
10+
11+
func NewService(repository Repository) *Service {
12+
return &Service{
13+
repo: repository,
14+
}
915
}
1016

1117
func (s Service) Create(ctx context.Context, ns Namespace) (Namespace, error) {
12-
return s.Repo.CreateNamespace(ctx, ns)
18+
return s.repo.Create(ctx, ns)
1319
}
1420

1521
func (s Service) Update(ctx context.Context, ns Namespace) (Namespace, error) {
16-
return s.Repo.UpdateNamespace(ctx, ns)
22+
return s.repo.Update(ctx, ns)
1723
}
1824

1925
func (s Service) List(ctx context.Context) ([]string, error) {
20-
return s.Repo.ListNamespaces(ctx)
26+
return s.repo.List(ctx)
2127
}
2228

2329
func (s Service) Get(ctx context.Context, name string) (Namespace, error) {
24-
return s.Repo.GetNamespace(ctx, name)
30+
return s.repo.Get(ctx, name)
2531
}
2632

2733
func (s Service) Delete(ctx context.Context, name string) error {
28-
return s.Repo.DeleteNamespace(ctx, name)
34+
return s.repo.Delete(ctx, name)
2935
}

core/schema/mocks/namespace_service.go

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

0 commit comments

Comments
 (0)