/
phone_number_validated.go
46 lines (39 loc) · 1.9 KB
/
phone_number_validated.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
package command_handler
import (
"context"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/config"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/domain/phone_number/aggregate"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/domain/phone_number/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 PhoneNumberValidatedCommandHandler interface {
Handle(ctx context.Context, cmd *command.PhoneNumberValidatedCommand) error
}
type phoneNumberValidatedCommandHandler struct {
log logger.Logger
cfg *config.Config
es eventstore.AggregateStore
}
func NewPhoneNumberValidatedCommandHandler(log logger.Logger, cfg *config.Config, es eventstore.AggregateStore) PhoneNumberValidatedCommandHandler {
return &phoneNumberValidatedCommandHandler{log: log, cfg: cfg, es: es}
}
func (h *phoneNumberValidatedCommandHandler) Handle(ctx context.Context, cmd *command.PhoneNumberValidatedCommand) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "PhoneNumberValidatedCommandHandler.Handle")
defer span.Finish()
tracing.SetCommandHandlerSpanTags(ctx, span, cmd.Tenant, cmd.LoggedInUserId)
span.LogFields(log.String("ObjectID", cmd.ObjectID))
phoneNumberAggregate, err := aggregate.LoadPhoneNumberAggregate(ctx, h.es, cmd.Tenant, cmd.ObjectID)
if err != nil {
tracing.TraceErr(span, err)
return err
}
if err = phoneNumberAggregate.HandleCommand(ctx, cmd); err != nil {
tracing.TraceErr(span, err)
return err
}
return h.es.Save(ctx, phoneNumberAggregate)
}