forked from raystack/optimus
/
namespace_service.go
35 lines (27 loc) · 1.02 KB
/
namespace_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package service
import (
"context"
"github.com/goto/optimus/core/tenant"
)
type NamespaceRepository interface {
Save(ctx context.Context, namespace *tenant.Namespace) error
GetByName(context.Context, tenant.ProjectName, tenant.NamespaceName) (*tenant.Namespace, error)
GetAll(context.Context, tenant.ProjectName) ([]*tenant.Namespace, error)
}
type NamespaceService struct {
nsRepo NamespaceRepository
}
func (ns NamespaceService) Save(ctx context.Context, namespace *tenant.Namespace) error {
return ns.nsRepo.Save(ctx, namespace)
}
func (ns NamespaceService) Get(ctx context.Context, projName tenant.ProjectName, namespaceName tenant.NamespaceName) (*tenant.Namespace, error) {
return ns.nsRepo.GetByName(ctx, projName, namespaceName)
}
func (ns NamespaceService) GetAll(ctx context.Context, projectName tenant.ProjectName) ([]*tenant.Namespace, error) {
return ns.nsRepo.GetAll(ctx, projectName)
}
func NewNamespaceService(nsRepo NamespaceRepository) *NamespaceService {
return &NamespaceService{
nsRepo: nsRepo,
}
}