conversion

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package conversion handles currency conversion events and persistence logic.

Package conversion handles currency conversion events and logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleCurrencyConverted

func HandleCurrencyConverted(
	uow repository.UnitOfWork,
	logger *slog.Logger) func(
	context.Context,
	events.Event,
) error

HandleCurrencyConverted persists CurrencyConverted events.

func HandleRequested

func HandleRequested(
	bus eventbus.Bus,
	exchangeRegistry registry.Provider,
	exchangeRateProvider exchangeprovider.Exchange,
	logger *slog.Logger,
	factories map[string]EventFactory,
) func(ctx context.Context, e events.Event) error

HandleRequested processes ConversionRequestedEvent and delegates to a flow-specific factory to create the next event.

func NewValidConversionInfo

func NewValidConversionInfo(
	fromCurrency, toCurrency string,
	rateValue float64,
) *exchange.RateInfo

NewValidConversionInfo returns a fully valid Info for use in tests.

func NewValidConversionRequestedEvent

func NewValidConversionRequestedEvent(
	flow events.FlowEvent,
	transactionID uuid.UUID,
	amount money.Money,
	to string,
) *events.CurrencyConversionRequested

NewValidConversionRequestedEvent returns a fully valid ConversionRequestedEvent for use in tests.

Types

type DepositEventFactory

type DepositEventFactory struct{}

DepositEventFactory creates a DepositCurrencyConverted event from a CurrencyConverted event.

func (*DepositEventFactory) CreateNextEvent

func (f *DepositEventFactory) CreateNextEvent(
	cc *events.CurrencyConverted,
) events.Event

CreateNextEvent creates DepositCurrencyConverted with converted event

type EventFactory

type EventFactory interface {
	// CreateNextEvent creates and returns the event that should be
	// emitted after a successful currency conversion.
	// It takes a CurrencyConverted event that contains all the necessary information
	// including the converted amount to create the next event in the flow.
	CreateNextEvent(cc *events.CurrencyConverted) events.Event
}

EventFactory defines the interface for creating the next event after a currency conversion. Each business flow (deposit, withdraw, etc.) will have its own implementation of this factory to construct the appropriate flow-specific event after currency conversion.

type TransferEventFactory

type TransferEventFactory struct{}

TransferEventFactory creates a TransferCurrencyConverted event from a CurrencyConverted event.

func (*TransferEventFactory) CreateNextEvent

func (f *TransferEventFactory) CreateNextEvent(
	cc *events.CurrencyConverted,
) events.Event

CreateNextEvent creates TransferCurrencyConverted with converted event

type WithdrawEventFactory

type WithdrawEventFactory struct{}

WithdrawEventFactory creates a WithdrawCurrencyConverted event from a CurrencyConverted event.

func (*WithdrawEventFactory) CreateNextEvent

func (f *WithdrawEventFactory) CreateNextEvent(
	cc *events.CurrencyConverted,
) events.Event

CreateNextEvent creates WithdrawCurrencyConverted with converted event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL