-
Notifications
You must be signed in to change notification settings - Fork 12
/
domain_service.go
55 lines (49 loc) · 2.16 KB
/
domain_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package service
import (
"context"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/entity"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/repository"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/common"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/logger"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
neo4jentity "github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/entity"
)
type DomainService interface {
GetDomainsForOrganizations(ctx context.Context, organizationIds []string) (*entity.DomainEntities, error)
}
type domainService struct {
log logger.Logger
repositories *repository.Repositories
}
func NewDomainService(log logger.Logger, repository *repository.Repositories) DomainService {
return &domainService{
log: log,
repositories: repository,
}
}
func (s *domainService) GetDomainsForOrganizations(ctx context.Context, organizationIds []string) (*entity.DomainEntities, error) {
domains, err := s.repositories.DomainRepository.GetForOrganizations(ctx, common.GetTenantFromContext(ctx), organizationIds)
if err != nil {
return nil, err
}
domainEntities := entity.DomainEntities{}
for _, v := range domains {
domainEntity := s.mapDbNodeToDomainEntity(*v.Node)
domainEntity.DataloaderKey = v.LinkedNodeId
domainEntities = append(domainEntities, *domainEntity)
}
return &domainEntities, nil
}
func (s *domainService) mapDbNodeToDomainEntity(dbNode dbtype.Node) *entity.DomainEntity {
props := utils.GetPropsFromNode(dbNode)
domain := entity.DomainEntity{
Id: utils.GetStringPropOrEmpty(props, "id"),
Domain: utils.GetStringPropOrEmpty(props, "domain"),
CreatedAt: utils.GetTimePropOrEpochStart(props, "createdAt"),
UpdatedAt: utils.GetTimePropOrEpochStart(props, "updatedAt"),
AppSource: utils.GetStringPropOrEmpty(props, "appSource"),
Source: neo4jentity.GetDataSource(utils.GetStringPropOrEmpty(props, "source")),
}
return &domain
}