-
Notifications
You must be signed in to change notification settings - Fork 12
/
log_entry_service.go
62 lines (55 loc) · 2.67 KB
/
log_entry_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
56
57
58
59
60
61
62
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/tracing"
"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"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
type LogEntryService interface {
GetById(ctx context.Context, logEntryId string) (*entity.LogEntryEntity, error)
mapDbNodeToLogEntryEntity(node *dbtype.Node) *entity.LogEntryEntity
}
type logEntryService struct {
log logger.Logger
repositories *repository.Repositories
}
func NewLogEntryService(log logger.Logger, repositories *repository.Repositories) LogEntryService {
return &logEntryService{
log: log,
repositories: repositories,
}
}
func (s *logEntryService) GetById(ctx context.Context, logEntryId string) (*entity.LogEntryEntity, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "LogEntryService.GetById")
defer span.Finish()
tracing.SetDefaultServiceSpanTags(ctx, span)
span.LogFields(log.String("logEntryId", logEntryId))
logEntryDbNode, err := s.repositories.Neo4jRepositories.LogEntryReadRepository.GetById(ctx, common.GetTenantFromContext(ctx), logEntryId)
if err != nil {
tracing.TraceErr(span, err)
return nil, err
}
return s.mapDbNodeToLogEntryEntity(logEntryDbNode), nil
}
func (s *logEntryService) mapDbNodeToLogEntryEntity(node *dbtype.Node) *entity.LogEntryEntity {
props := utils.GetPropsFromNode(*node)
logEntry := entity.LogEntryEntity{
Id: utils.GetStringPropOrEmpty(props, "id"),
Content: utils.GetStringPropOrEmpty(props, "content"),
ContentType: utils.GetStringPropOrEmpty(props, "contentType"),
CreatedAt: utils.GetTimePropOrEpochStart(props, "createdAt"),
UpdatedAt: utils.GetTimePropOrEpochStart(props, "updatedAt"),
StartedAt: utils.GetTimePropOrEpochStart(props, "startedAt"),
AppSource: utils.GetStringPropOrEmpty(props, "appSource"),
Source: neo4jentity.GetDataSource(utils.GetStringPropOrEmpty(props, "source")),
SourceOfTruth: neo4jentity.GetDataSource(utils.GetStringPropOrEmpty(props, "sourceOfTruth")),
}
return &logEntry
}