-
Notifications
You must be signed in to change notification settings - Fork 12
/
contact_service.go
34 lines (28 loc) · 1.08 KB
/
contact_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
package service
import (
"context"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-customer-os-data/entity"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-customer-os-data/repository"
)
type ContactService interface {
GetIdForReferencedContact(ctx context.Context, tenant, externalSystem string, contact entity.ReferencedContact) (string, error)
}
type contactService struct {
repositories *repository.Repositories
}
func NewContactService(repositories *repository.Repositories) ContactService {
return &contactService{
repositories: repositories,
}
}
func (s *contactService) GetIdForReferencedContact(ctx context.Context, tenant, externalSystemId string, contact entity.ReferencedContact) (string, error) {
if !contact.Available() {
return "", nil
}
if contact.ReferencedById() {
return s.repositories.ContactRepository.GetContactIdById(ctx, tenant, contact.Id)
} else if contact.ReferencedByExternalId() {
return s.repositories.ContactRepository.GetContactIdByExternalId(ctx, tenant, contact.ExternalId, externalSystemId)
}
return "", nil
}