Documentation ¶
Overview ¶
Package service provides the core business logic for handling wallet and transaction operations. It includes services for deposit, withdrawal, and transaction management. Each service interacts with the underlying repositories for data persistence and business rules enforcement. The services also manage Redis caching for balance data to optimize performance and reduce database load.
The WithdrawService is responsible for handling user withdrawals, ensuring that the user has sufficient balance, recording the transaction, updating the balance, and caching the new balance in Redis. The service ensures thread-safety during withdrawal operations by using locks to prevent race conditions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BalanceService ¶
type BalanceService struct {
// contains filtered or unexported fields
}
BalanceService provides services related to user balance operations. It interacts with the WalletRepository to manage user wallet data, and uses the database and Redis client for storing and retrieving balance information.
func NewBalanceService ¶
func NewBalanceService(dbConn *sqlx.DB, redisClient *redis.Client) *BalanceService
NewBalanceService creates a new instance of BalanceService with the provided database connection and Redis client. It initializes the service with a WalletRepository to handle wallet-related database operations.
func (*BalanceService) GetBalance ¶
GetBalance function retrieves the user's balance. It first attempts to obtain the balance from the Redis cache. If the data is not found in the Redis cache (a cache miss occurs), it then queries the database to get the balance.
type DepositService ¶
type DepositService struct {
// contains filtered or unexported fields
}
DepositService provides methods for handling deposit operations. It interacts with the WalletRepository and TransactionRepository to manage user balances and transaction records.
func NewDepositService ¶
func NewDepositService(dbConn *sqlx.DB, redisClient *redis.Client) *DepositService
NewDepositService creates a new instance of DepositService. It initializes the service with the provided database connection and Redis client.
type TransactionService ¶
type TransactionService struct {
// contains filtered or unexported fields
}
TransactionService provides methods for managing transactions. It interacts with the TransactionRepository to handle transaction-related operations.
func NewTransactionService ¶
func NewTransactionService(dbConn *sqlx.DB) *TransactionService
NewTransactionService creates a new instance of TransactionService with the provided database connection. It initializes the service with a TransactionRepository to handle transaction-related database operations.
func (*TransactionService) GetTransactions ¶
func (s *TransactionService) GetTransactions(ctx context.Context, userID int) ([]model.Transaction, error)
GetTransactions retrieves the transaction records of the specified user
type TransferService ¶
type TransferService struct {
// contains filtered or unexported fields
}
TransferService handles fund transfers, including balance updates and transaction records.
func NewTransferService ¶
func NewTransferService(dbConn *sqlx.DB, redisClient *redis.Client) *TransferService
NewTransferService initializes and returns a TransferService instance with the required repositories and database/Redis clients.
type WithdrawService ¶
type WithdrawService struct {
// contains filtered or unexported fields
}
WithdrawService provides methods for handling withdrawal operations. It interacts with the WalletRepository and TransactionRepository to manage user balances and transaction records.
func NewWithdrawService ¶
func NewWithdrawService(dbConn *sqlx.DB, redisClient *redis.Client) *WithdrawService
NewWithdrawService creates a new instance of WithdrawService. It initializes the service with the provided database connection and Redis client, and sets up the necessary repositories for wallet and transaction management.