-
Notifications
You must be signed in to change notification settings - Fork 12
/
replace_summary.go
50 lines (41 loc) · 1.95 KB
/
replace_summary.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
package command_handler
import (
"context"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/validator"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/domain/interaction_event/aggregate"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/domain/interaction_event/command"
"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/logger"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/tracing"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
type ReplaceSummaryCommandHandler interface {
Handle(ctx context.Context, cmd *command.ReplaceSummaryCommand) error
}
type replaceSummaryCommandHandler struct {
log logger.Logger
es eventstore.AggregateStore
}
func NewReplaceSummaryCommandHandler(log logger.Logger, es eventstore.AggregateStore) ReplaceSummaryCommandHandler {
return &replaceSummaryCommandHandler{log: log, es: es}
}
func (h *replaceSummaryCommandHandler) Handle(ctx context.Context, cmd *command.ReplaceSummaryCommand) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "ReplaceSummaryCommandHandler.Handle")
defer span.Finish()
span.LogFields(log.String("Tenant", cmd.Tenant), log.String("ObjectID", cmd.ObjectID))
if err := validator.GetValidator().Struct(cmd); err != nil {
tracing.TraceErr(span, err)
return err
}
interactionEventAggregate, err := aggregate.LoadInteractionEventAggregate(ctx, h.es, cmd.Tenant, cmd.ObjectID)
if err != nil {
tracing.TraceErr(span, err)
return err
}
if err = interactionEventAggregate.ReplaceSummary(ctx, cmd.Tenant, cmd.Summary, cmd.ContentType, cmd.UpdatedAt); err != nil {
tracing.TraceErr(span, err)
return err
}
return h.es.Save(ctx, interactionEventAggregate)
}