-
Notifications
You must be signed in to change notification settings - Fork 0
/
company.go
56 lines (48 loc) · 1.76 KB
/
company.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package logic
import (
"errors"
v1 "github.com/klovercloud-ci-cd/integration-manager/core/v1"
"github.com/klovercloud-ci-cd/integration-manager/core/v1/repository"
"github.com/klovercloud-ci-cd/integration-manager/core/v1/service"
"github.com/klovercloud-ci-cd/integration-manager/enums"
)
type companyService struct {
repo repository.CompanyRepository
applicationMetadataRepository repository.ApplicationMetadataRepository
client service.HttpClient
}
func (c companyService) Store(company v1.Company) error {
if company.Id == "" {
return errors.New("[ERROR]: No company id is given")
}
data := c.GetByName(company.Name, v1.StatusQueryOption{Option: enums.ACTIVE})
if data.Id != "" {
return errors.New("[ERROR]: Company name already exists")
}
return c.repo.Store(company)
}
func (c companyService) Delete(companyId string) error {
err := c.repo.Delete(companyId)
if err != nil {
return err
}
return nil
}
func (c companyService) GetCompanies(option v1.CompanyQueryOption, status v1.StatusQueryOption) []v1.Company {
companies, _ := c.repo.GetCompanies(option, status)
return companies
}
func (c companyService) GetByCompanyId(id string) v1.Company {
return c.repo.GetByCompanyId(id)
}
func (c companyService) GetByName(name string, status v1.StatusQueryOption) v1.Company {
return c.repo.GetByName(name, status)
}
// NewCompanyService returns Company type service
func NewCompanyService(repo repository.CompanyRepository, applicationMetadataRepository repository.ApplicationMetadataRepository, client service.HttpClient) service.Company {
return &companyService{
repo: repo,
applicationMetadataRepository: applicationMetadataRepository,
client: client,
}
}