command

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Source    string = "midaz"
	EventType string = "transaction"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type UseCase

type UseCase struct {
	// TransactionRepo provides an abstraction on top of the transaction data source.
	TransactionRepo transaction.Repository

	// OperationRepo provides an abstraction on top of the operation data source.
	OperationRepo operation.Repository

	// AssetRateRepo provides an abstraction on top of the asset rate data source.
	AssetRateRepo assetrate.Repository

	// BalanceRepo provides an abstraction on top of the balance data source.
	BalanceRepo balance.Repository

	// OperationRouteRepo provides an abstraction on top of the operation route data source.
	OperationRouteRepo operationroute.Repository

	// TransactionRouteRepo provides an abstraction on top of the transaction route data source.
	TransactionRouteRepo transactionroute.Repository

	// MetadataRepo provides an abstraction on top of the metadata data source.
	MetadataRepo mongodb.Repository

	// RabbitMQRepo provides an abstraction on top of the producer rabbitmq.
	RabbitMQRepo rabbitmq.ProducerRepository

	// RedisRepo provides an abstraction on top of the redis consumer.
	RedisRepo redis.RedisRepository
}

UseCase is a struct that aggregates various repositories for simplified access in use case implementations.

func (*UseCase) CheckHealth added in v3.5.0

func (uc *UseCase) CheckHealth(ctx context.Context) error

CheckHealth returns nil for unified mode (in-process calls don't need health checks).

func (*UseCase) CreateAccountingRouteCache

func (uc *UseCase) CreateAccountingRouteCache(ctx context.Context, route *mmodel.TransactionRoute) error

CreateAccountingRouteCache creates a cache for the accounting route. It converts the transaction route into a cache structure and stores it in Redis. The cache structure is a map of operation route ids to their type and account rule. The operation route ids are the uuids of the operation routes in the transaction route. The type is the type of the operation route (debit or credit). The account rule is the account rule of the operation route.

func (*UseCase) CreateAdditionalBalance added in v3.3.0

func (uc *UseCase) CreateAdditionalBalance(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, cbi *mmodel.CreateAdditionalBalance) (*mmodel.Balance, error)

CreateAdditionalBalance creates a new additional balance.

func (*UseCase) CreateBTOExecuteSync

func (uc *UseCase) CreateBTOExecuteSync(ctx context.Context, organizationID, ledgerID uuid.UUID, parseDSL *pkgTransaction.Transaction, validate *pkgTransaction.Responses, blc []*mmodel.Balance, tran *transaction.Transaction) error

CreateBTOExecuteSync func that send balances, transaction and operations to execute in database sync.

func (*UseCase) CreateBTOSync

func (uc *UseCase) CreateBTOSync(ctx context.Context, data mmodel.Queue) error

CreateBTOSync func that create balance transaction operations synchronously

func (*UseCase) CreateBalance

func (uc *UseCase) CreateBalance(ctx context.Context, data mmodel.Queue) error

func (*UseCase) CreateBalanceSync added in v3.4.1

func (uc *UseCase) CreateBalanceSync(ctx context.Context, input mmodel.CreateBalanceInput) (*mmodel.Balance, error)

CreateBalanceSync creates a new balance synchronously using the request-supplied properties. If key != "default", it validates that the default balance exists and that the account type allows additional balances. This method implements mbootstrap.BalancePort, allowing the transaction module to be used directly by the onboarding module in unified ledger mode.

func (*UseCase) CreateBalanceTransactionOperationsAsync

func (uc *UseCase) CreateBalanceTransactionOperationsAsync(ctx context.Context, data mmodel.Queue) error

CreateBalanceTransactionOperationsAsync func that is responsible to create all transactions at the same async.

func (*UseCase) CreateMetadata

func (uc *UseCase) CreateMetadata(ctx context.Context, logger libLog.Logger, metadata map[string]any, o *operation.Operation) error

CreateMetadata func that create metadata into operations

func (*UseCase) CreateMetadataAsync

func (uc *UseCase) CreateMetadataAsync(ctx context.Context, logger libLog.Logger, metadata map[string]any, ID string, collection string) error

CreateMetadataAsync func that create metadata into operations

func (*UseCase) CreateMetadataIndex added in v3.5.0

func (uc *UseCase) CreateMetadataIndex(ctx context.Context, entityName string, input *mmodel.CreateMetadataIndexInput) (*mmodel.MetadataIndex, error)

CreateMetadataIndex creates a new metadata index.

func (*UseCase) CreateOperation

func (uc *UseCase) CreateOperation(ctx context.Context, balances []*mmodel.Balance, transactionID string, dsl *pkgTransaction.Transaction, validate pkgTransaction.Responses, result chan []*operation.Operation, err chan error)

CreateOperation creates a new operation based on transaction id and persisting data in the repository.

func (*UseCase) CreateOperationRoute

func (uc *UseCase) CreateOperationRoute(ctx context.Context, organizationID, ledgerID uuid.UUID, payload *mmodel.CreateOperationRouteInput) (*mmodel.OperationRoute, error)

CreateOperationRoute creates a new operation route.

func (*UseCase) CreateOrCheckIdempotencyKey

func (uc *UseCase) CreateOrCheckIdempotencyKey(ctx context.Context, organizationID, ledgerID uuid.UUID, key, hash string, ttl time.Duration) (*string, error)

func (*UseCase) CreateOrUpdateAssetRate

func (uc *UseCase) CreateOrUpdateAssetRate(ctx context.Context, organizationID, ledgerID uuid.UUID, cari *assetrate.CreateAssetRateInput) (*assetrate.AssetRate, error)

CreateOrUpdateAssetRate creates or updates an asset rate.

func (*UseCase) CreateOrUpdateTransaction

func (uc *UseCase) CreateOrUpdateTransaction(ctx context.Context, logger libLog.Logger, tracer trace.Tracer, t transaction.TransactionQueue) (*transaction.Transaction, error)

CreateOrUpdateTransaction func that is responsible to create or update a transaction.

func (*UseCase) CreateTransaction

func (uc *UseCase) CreateTransaction(ctx context.Context, organizationID, ledgerID, transactionID uuid.UUID, t *pkgTransaction.Transaction) (*transaction.Transaction, error)

CreateTransaction creates a new transaction persisting data in the repository.

func (*UseCase) CreateTransactionRoute

func (uc *UseCase) CreateTransactionRoute(ctx context.Context, organizationID, ledgerID uuid.UUID, payload *mmodel.CreateTransactionRouteInput) (*mmodel.TransactionRoute, error)

CreateTransactionRoute creates a new transaction route. It returns the created transaction route and an error if the operation fails.

func (*UseCase) DeleteAllBalancesByAccountID added in v3.5.0

func (uc *UseCase) DeleteAllBalancesByAccountID(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, requestID string) error

DeleteAllBalancesByAccountID delete all balances by account id in the repository.

func (*UseCase) DeleteBalance

func (uc *UseCase) DeleteBalance(ctx context.Context, organizationID, ledgerID, balanceID uuid.UUID) error

DeleteBalance delete balance in the repository.

func (*UseCase) DeleteMetadataIndex added in v3.5.0

func (uc *UseCase) DeleteMetadataIndex(ctx context.Context, entityName, indexName string) error

DeleteMetadataIndex removes a metadata index from a specific entity collection.

func (*UseCase) DeleteOperationRouteByID

func (uc *UseCase) DeleteOperationRouteByID(ctx context.Context, organizationID, ledgerID uuid.UUID, id uuid.UUID) error

DeleteOperationRouteByID is a method that deletes Operation Route information.

func (*UseCase) DeleteTransactionRouteByID

func (uc *UseCase) DeleteTransactionRouteByID(ctx context.Context, organizationID, ledgerID, transactionRouteID uuid.UUID) error

DeleteTransactionRouteByID delete a transaction route from the repository by ids. It will also delete the relationships between the transaction route and the operation routes.

func (*UseCase) DeleteTransactionRouteCache

func (uc *UseCase) DeleteTransactionRouteCache(ctx context.Context, organizationID, ledgerID, transactionRouteID uuid.UUID) error

DeleteTransactionRouteCache deletes the cache for a transaction route.

func (*UseCase) ReloadOperationRouteCache

func (uc *UseCase) ReloadOperationRouteCache(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error

ReloadOperationRouteCache reloads the cache for all transaction routes associated with the given operation route. It retrieves all transaction routes linked to the operation route and recreates their cache entries.

func (*UseCase) RemoveTransactionFromRedisQueue added in v3.3.0

func (uc *UseCase) RemoveTransactionFromRedisQueue(ctx context.Context, logger libLog.Logger, organizationID, ledgerID uuid.UUID, transactionID string)

RemoveTransactionFromRedisQueue func that remove transaction from redis queue

func (*UseCase) SendBTOExecuteAsync

func (uc *UseCase) SendBTOExecuteAsync(ctx context.Context, organizationID, ledgerID uuid.UUID, parseDSL *pkgTransaction.Transaction, validate *pkgTransaction.Responses, blc []*mmodel.Balance, tran *transaction.Transaction) error

SendBTOExecuteAsync func that send balances, transaction and operations to a queue to execute async.

func (*UseCase) SendLogTransactionAuditQueue

func (uc *UseCase) SendLogTransactionAuditQueue(ctx context.Context, operations []*operation.Operation, organizationID, ledgerID, transactionID uuid.UUID)

SendLogTransactionAuditQueue sends transaction audit log data to a message queue for processing and storage. ctx is the request-scoped context for cancellation and deadlines. operations is the list of operations to be logged in the audit queue. organizationID is the UUID of the associated organization. ledgerID is the UUID of the ledger linked to the transaction. transactionID is the UUID of the transaction being logged.

func (*UseCase) SendTransactionEvents

func (uc *UseCase) SendTransactionEvents(ctx context.Context, tran *transaction.Transaction)

func (*UseCase) SendTransactionToRedisQueue added in v3.3.0

func (uc *UseCase) SendTransactionToRedisQueue(ctx context.Context, organizationID, ledgerID, transactionID uuid.UUID, parserDSL pkgTransaction.Transaction, validate *pkgTransaction.Responses, transactionStatus string, transactionDate time.Time) error

SendTransactionToRedisQueue func that send transaction to redis queue

func (*UseCase) SetTransactionIdempotencyMapping added in v3.3.11

func (uc *UseCase) SetTransactionIdempotencyMapping(ctx context.Context, organizationID, ledgerID uuid.UUID, transactionID, idempotencyKey string, ttl time.Duration)

SetTransactionIdempotencyMapping stores the reverse mapping from transactionID to idempotency key. This allows looking up which idempotency key corresponds to a given transaction.

func (*UseCase) SetValueOnExistingIdempotencyKey

func (uc *UseCase) SetValueOnExistingIdempotencyKey(ctx context.Context, organizationID, ledgerID uuid.UUID, key, hash string, t transaction.Transaction, ttl time.Duration)

SetValueOnExistingIdempotencyKey func that set value on idempotency key to return to user.

func (*UseCase) SyncBalance added in v3.4.1

func (uc *UseCase) SyncBalance(ctx context.Context, organizationID, ledgerID uuid.UUID, balance mmodel.BalanceRedis) (bool, error)

SyncBalance is responsible to sync balance from redis to database. The cache balance might take a long time to be persisted in the database, so this function syncs the balance before the key expires, to avoid data inconsistency.

func (*UseCase) TransactionExecute

func (uc *UseCase) TransactionExecute(ctx context.Context, organizationID, ledgerID uuid.UUID, parseDSL *pkgTransaction.Transaction, validate *pkgTransaction.Responses, blc []*mmodel.Balance, tran *transaction.Transaction) error

TransactionExecute func that send balances, transaction and operations to execute sync/async.

func (*UseCase) Update

func (uc *UseCase) Update(ctx context.Context, organizationID, ledgerID, balanceID uuid.UUID, update mmodel.UpdateBalance) (*mmodel.Balance, error)

Update balance in the repository and returns the updated balance. Overlays Redis cached values for Available, OnHold, and Version to ensure freshest data.

func (*UseCase) UpdateBalances

func (uc *UseCase) UpdateBalances(ctx context.Context, organizationID, ledgerID uuid.UUID, validate pkgTransaction.Responses, balances []*mmodel.Balance) error

UpdateBalances func that is responsible to update balances without select for update.

func (*UseCase) UpdateMetadata

func (uc *UseCase) UpdateMetadata(ctx context.Context, entityName, entityID string, metadata map[string]any) (map[string]any, error)

func (*UseCase) UpdateOperation

func (uc *UseCase) UpdateOperation(ctx context.Context, organizationID, ledgerID, transactionID, operationID uuid.UUID, uoi *operation.UpdateOperationInput) (*operation.Operation, error)

UpdateOperation update an operation from the repository by given id.

func (*UseCase) UpdateOperationRoute

func (uc *UseCase) UpdateOperationRoute(ctx context.Context, organizationID, ledgerID uuid.UUID, id uuid.UUID, input *mmodel.UpdateOperationRouteInput) (*mmodel.OperationRoute, error)

func (*UseCase) UpdateTransaction

func (uc *UseCase) UpdateTransaction(ctx context.Context, organizationID, ledgerID, transactionID uuid.UUID, uti *transaction.UpdateTransactionInput) (*transaction.Transaction, error)

UpdateTransaction update a transaction from the repository by given id.

func (*UseCase) UpdateTransactionRoute

func (uc *UseCase) UpdateTransactionRoute(ctx context.Context, organizationID, ledgerID, id uuid.UUID, input *mmodel.UpdateTransactionRouteInput) (*mmodel.TransactionRoute, error)

UpdateTransactionRoute updates a transaction route by its ID. It returns the updated transaction route and an error if the operation fails.

func (*UseCase) UpdateTransactionStatus

func (uc *UseCase) UpdateTransactionStatus(ctx context.Context, tran *transaction.Transaction) (*transaction.Transaction, error)

UpdateTransactionStatus update a status transaction from the repository by given id.

Jump to

Keyboard shortcuts

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