35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
// Package invite runs asynchronous invite validity consumers.
|
|
package invite
|
|
|
|
import (
|
|
"context"
|
|
|
|
invitedomain "hyapp/services/user-service/internal/domain/invite"
|
|
)
|
|
|
|
// Repository applies wallet recharge events to user-service invite progress.
|
|
type Repository interface {
|
|
ApplyRechargeEvent(ctx context.Context, event invitedomain.RechargeEvent) (invitedomain.RechargeApplyResult, error)
|
|
}
|
|
|
|
// Service owns the invite validity event consumer.
|
|
type Service struct {
|
|
repository Repository
|
|
}
|
|
|
|
// New creates an invite service with the repository that owns idempotent application.
|
|
func New(repository Repository) *Service {
|
|
return &Service{repository: repository}
|
|
}
|
|
|
|
// ConsumeWalletRechargeEvent applies one MQ-delivered wallet recharge fact.
|
|
func (s *Service) ConsumeWalletRechargeEvent(ctx context.Context, event invitedomain.RechargeEvent) (invitedomain.RechargeApplyResult, error) {
|
|
if s == nil || s.repository == nil {
|
|
return invitedomain.RechargeApplyResult{}, nil
|
|
}
|
|
if event.EventType != invitedomain.RechargeEventWalletRecorded {
|
|
return invitedomain.RechargeApplyResult{Skipped: true, Reason: "unsupported_event_type"}, nil
|
|
}
|
|
return s.repository.ApplyRechargeEvent(ctx, event)
|
|
}
|