worth_service_subscriber.go
948 字节
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
package subscriber
import (
"fmt"
"github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
)
type WorthServiceSubscriber struct {
}
func (subscriber *WorthServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
worthServiceGateway, err := factory.CreateWorthServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil
}
switch domainEvent.EventType() {
case event.USER_CHANGE_PHONE:
phoneChangedEvent := domainEvent.(*event.PhoneChanged)
data, err := worthServiceGateway.ChangePhoneCallback(phoneChangedEvent.OldPhone, phoneChangedEvent.NewPhone)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
}
return nil
}
func (subscriber *WorthServiceSubscriber) SubscribedToEventTypes() []string {
return []string{
event.USER_CHANGE_PHONE,
}
}