-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.go
31 lines (25 loc) · 1.21 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 GetOpportunityObjectID(aggregateID string, tenant string) string {
return aggregate.GetAggregateObjectID(aggregateID, tenant, OpportunityAggregateType)
}
func LoadOpportunityAggregate(ctx context.Context, eventStore eventstore.AggregateStore, tenant, objectID string) (*OpportunityAggregate, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "LoadOpportunityAggregate")
defer span.Finish()
span.SetTag(tracing.SpanTagTenant, tenant)
span.LogFields(log.String("ObjectID", objectID))
opportunityAggregate := NewOpportunityAggregateWithTenantAndID(tenant, objectID)
err := aggregate.LoadAggregate(ctx, eventStore, opportunityAggregate, *eventstore.NewLoadAggregateOptions())
if err != nil {
tracing.TraceErr(span, err)
return nil, err
}
return opportunityAggregate, nil
}