worth_service_subscriber.go 948 字节
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,
	}
}