pg_change_phone_service.go 950 字节
package domain_service

import (
	"fmt"
	coreDomain "github.com/linmadan/egglib-go/core/domain"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
)

type ChangePhoneService struct {
	coreDomain.BaseEventPublisher
	transactionContext *pgTransaction.TransactionContext
}

func (service *ChangePhoneService) ChangePhone(oldPhone string, newPhone string) error {
	changePhoneEvent := new(event.PhoneChanged)
	changePhoneEvent.OldPhone = oldPhone
	changePhoneEvent.NewPhone = newPhone
	if err := service.Publish(changePhoneEvent); err != nil {
		return err
	}
	return nil
}

func NewChangePhoneService(transactionContext *pgTransaction.TransactionContext) (*ChangePhoneService, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &ChangePhoneService{
			transactionContext: transactionContext,
		}, nil
	}
}