-
Notifications
You must be signed in to change notification settings - Fork 12
/
user_service.go
52 lines (41 loc) · 1.32 KB
/
user_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
package service
import (
"context"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-gmail/entity"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-gmail/repository"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
)
type UserService interface {
GetAllUsersForTenant(ctx context.Context, tenant string) ([]*entity.UserEntity, error)
}
type userService struct {
repositories *repository.Repositories
}
func NewUserService(repository *repository.Repositories) UserService {
return &userService{
repositories: repository,
}
}
func (s *userService) GetAllUsersForTenant(ctx context.Context, tenant string) ([]*entity.UserEntity, error) {
nodes, err := s.repositories.UserRepository.GetAllForTenant(ctx, tenant)
if err != nil {
return nil, fmt.Errorf("GetAllUsersForTenant: %w", err)
}
users := make([]*entity.UserEntity, len(nodes))
for i, node := range nodes {
users[i] = s.mapDbNodeToUserEntity(node)
}
return users, nil
}
func (s *userService) mapDbNodeToUserEntity(dbNode *dbtype.Node) *entity.UserEntity {
if dbNode == nil {
return nil
}
props := utils.GetPropsFromNode(*dbNode)
user := entity.UserEntity{
Id: utils.GetStringPropOrEmpty(props, "id"),
}
return &user
}