-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.go
31 lines (25 loc) · 1.29 KB
/
utils.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
package aggregate
import (
"context"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/domain/common/aggregate"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/eventstore"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/tracing"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
func GetInteractionEventObjectID(aggregateID string, tenant string) string {
return aggregate.GetAggregateObjectID(aggregateID, tenant, InteractionEventAggregateType)
}
func LoadInteractionEventAggregate(ctx context.Context, eventStore eventstore.AggregateStore, tenant, objectID string) (*InteractionEventAggregate, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "LoadInteractionEventAggregate")
defer span.Finish()
span.LogFields(log.String("Tenant", tenant), log.String("ObjectID", objectID))
interactionEventAggregate := NewInteractionEventAggregateWithTenantAndID(tenant, objectID)
err := aggregate.LoadAggregate(ctx, eventStore, interactionEventAggregate, *eventstore.NewLoadAggregateOptions())
if err != nil {
tracing.TraceErr(span, err)
return nil, err
}
span.LogFields(log.Bool("AggregateExists", true))
return interactionEventAggregate, nil
}