Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateRandomId(min, max int) int
- func GenerateRandomizedAccount() *models.MerchantAccount
- func GenerateRandomizedAccountWithRandomId() *models.MerchantAccount
- func SetupTestDbConn()
- type ConnectionInitializationParams
- type Db
- func (db *Db) AccountActive(account *models.MerchantAccountORM) bool
- func (db *Db) ActivateAccount(ctx context.Context, id uint64) (bool, error)
- func (db *Db) CheckAccountExistenceStatus(ctx context.Context, id uint64) (bool, error)
- func (db *Db) CreateMerchantAccount(ctx context.Context, account *models.MerchantAccount) (*models.MerchantAccount, error)
- func (db *Db) DeactivateMerchantAccount(ctx context.Context, id uint64) (bool, error)
- func (db *Db) FindMerchantAccountByEmail(ctx context.Context, email string) (bool, error)
- func (db *Db) FindMerchantAccountByStripeAccountId(ctx context.Context, stripeConnectedAccountId string) (*models.MerchantAccount, error)
- func (db *Db) GetMerchantAccountById(ctx context.Context, id uint64, checkAccountActivationStatus bool) (*models.MerchantAccount, error)
- func (db *Db) SaveAccountRecord(ctx context.Context, acct *models.MerchantAccount) error
- func (db *Db) UpdateAccountOnboardStatus(ctx context.Context, account *models.MerchantAccountORM) error
- func (db *Db) UpdateMerchantAccount(ctx context.Context, id uint64, account *models.MerchantAccount) (*models.MerchantAccount, error)
- func (db *Db) ValidateAccount(ctx context.Context, account *models.MerchantAccountORM) error
- func (db *Db) ValidateAccountIds(ctx context.Context, account *models.MerchantAccountORM) error
- func (db *Db) ValidateAccountNotNil(ctx context.Context, account *models.MerchantAccountORM) error
- func (db *Db) ValidateAccountParameters(ctx context.Context, account *models.MerchantAccountORM) error
- type Interface
- type OperationType
- type TxFunc
Constants ¶
const ( DefaultMaxConnectionAttempts int = 3 DefaultMaxRetriesPerOperation int = 3 DefaultRetryTimeout time.Duration = 50 * time.Millisecond DefaultRetrySleepInterval time.Duration = 25 * time.Millisecond )
const (
EMPTY = ""
)
Variables ¶
var ( Conn *Db Port int = 6000 Host string = "localhost" User string = "merchant_component" Password string = "merchant_component" Dbname string = "merchant_component" DefaultDbConnParams = helper.DatabaseConnectionParams{ Host: Host, User: User, Password: Password, DatabaseName: Dbname, Port: Port, } DefaultConnInitializationParams = ConnectionInitializationParams{ ConnectionParams: &DefaultDbConnParams, Logger: zap.L(), MaxConnectionAttempts: DefaultMaxConnectionAttempts, MaxRetriesPerOperation: DefaultMaxRetriesPerOperation, RetryTimeOut: DefaultRetryTimeout, RetrySleepInterval: DefaultRetrySleepInterval, } )
Functions ¶
func GenerateRandomId ¶
GenerateRandomId generates a random id over a range
func GenerateRandomizedAccount ¶
func GenerateRandomizedAccount() *models.MerchantAccount
GenerateRandomizedAccount generates a random account
func GenerateRandomizedAccountWithRandomId ¶
func GenerateRandomizedAccountWithRandomId() *models.MerchantAccount
func SetupTestDbConn ¶
func SetupTestDbConn()
SetupTestDbConn sets up a database connection to the test db node
Types ¶
type ConnectionInitializationParams ¶
type ConnectionInitializationParams struct { // ConnectionParams outlines database connection parameters ConnectionParams *helper.DatabaseConnectionParams // Logger is the logging utility used by this object Logger *zap.Logger // MaxConnectionAttempts outlines the maximum connection attempts // to initiate against the database MaxConnectionAttempts int // MaxRetriesPerOperation defines the maximum retries to attempt per failed database // connection attempt MaxRetriesPerOperation int // RetryTimeOut defines the maximum time until a retry operation is observed as a // timed out operation RetryTimeOut time.Duration // RetrySleepInterval defines the amount of time between retry operations // that the system sleeps RetrySleepInterval time.Duration }
ConnectionInitializationParams represents connection initialization parameters for the database
type Db ¶
type Db struct { // Conn serves as the actual database connection object Conn *core_database.DatabaseConn // Logger is the logging utility used by this object Logger *zap.Logger // MaxConnectionAttempts outlines the maximum connection attempts // to initiate against the database MaxConnectionAttempts int // MaxRetriesPerOperation defines the maximum retries to attempt per failed database // connection attempt MaxRetriesPerOperation int // RetryTimeOut defines the maximum time until a retry operation is observed as a // timed out operation RetryTimeOut time.Duration // OperationSleepInterval defines the amount of time between retry operations // that the system sleeps OperationSleepInterval time.Duration }
Db withholds connection to a postgres database as well as a logging handler
func New ¶
func New(ctx context.Context, params *ConnectionInitializationParams) (*Db, error)
New creates a database connection and returns the connection object
func (*Db) AccountActive ¶
func (db *Db) AccountActive(account *models.MerchantAccountORM) bool
func (*Db) ActivateAccount ¶
ActivateAccount activates a business account and saves it to the database as long as it exists
the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage
func (*Db) CheckAccountExistenceStatus ¶
CheckAccountExistenceStatus checks if a merchant account exists solely off its Id
func (*Db) CreateMerchantAccount ¶
func (db *Db) CreateMerchantAccount(ctx context.Context, account *models.MerchantAccount) (*models.MerchantAccount, error)
CreateMerchantAccount creates a business account and saves it to the database the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage
func (*Db) DeactivateMerchantAccount ¶
DeactivateMerchantAccount deactivates a business account and updates the database
the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage
func (*Db) FindMerchantAccountByEmail ¶
FindMerchantAccountByEmail finds a merchant account by email
func (*Db) FindMerchantAccountByStripeAccountId ¶
func (db *Db) FindMerchantAccountByStripeAccountId(ctx context.Context, stripeConnectedAccountId string) (*models.MerchantAccount, error)
FindMerchantAccountByStripeAccountId finds a merchant account by stripe id
func (*Db) GetMerchantAccountById ¶
func (db *Db) GetMerchantAccountById(ctx context.Context, id uint64, checkAccountActivationStatus bool) (*models.MerchantAccount, error)
GetMerchantAccountById finds a merchant account by id
func (*Db) SaveAccountRecord ¶
SaveAccountRecord saves a record in the database
func (*Db) UpdateAccountOnboardStatus ¶
func (db *Db) UpdateAccountOnboardStatus(ctx context.Context, account *models.MerchantAccountORM) error
UpdateAccountOnboardStatus updates the onboarding status of a merchant account
func (*Db) UpdateMerchantAccount ¶
func (db *Db) UpdateMerchantAccount(ctx context.Context, id uint64, account *models.MerchantAccount) ( *models.MerchantAccount, error)
UpdateMerchantAccount updates a business account and saves it to the database as long as it exists
the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage
func (*Db) ValidateAccount ¶
ValidateAccount performs various account level validations
func (*Db) ValidateAccountIds ¶
ValidateAccountIds validates the existence of various ids associated with the account
func (*Db) ValidateAccountNotNil ¶
ValidateAccountNotNil ensures the account object is not nil
func (*Db) ValidateAccountParameters ¶
func (db *Db) ValidateAccountParameters(ctx context.Context, account *models.MerchantAccountORM) error
ValidateAccountParameters validates account params.
type Interface ¶
type Interface interface { // CreateMerchantAccount creates a merchant account record CreateMerchantAccount(ctx context.Context, account *models.MerchantAccount) (*models.MerchantAccount, error) // UpdateMerchantAccount updates a merchant account record assuming the record exists UpdateMerchantAccount(ctx context.Context, id uint64, account *models.MerchantAccount) (*models.MerchantAccount, error) // DeactivateMerchantAccount performs a "soft" delete of the merchant account record DeactivateMerchantAccount(ctx context.Context, id uint64) (bool, error) // GetMerchantAccountById returns a merchant account record if it exists GetMerchantAccountById(ctx context.Context, id uint64, checkAccountActivationStatus bool) (*models.MerchantAccount, error) // CheckAccountExistenceStatus asserts a given merchant account exists based on provided merchant account ID CheckAccountExistenceStatus(ctx context.Context, id uint64) (bool, error) // ActivateAccount activates a merchant account record ActivateAccount(ctx context.Context, id uint64) (bool, error) // FindMerchantAccountByStripeAccountId attempts to obtain a merchant account record based on the merchant's // stripe connected account ID FindMerchantAccountByStripeAccountId(ctx context.Context, stripeConnectedAccountId string) (*models.MerchantAccount, error) }
Interface provides an interface which any database tied to this service should implement
type OperationType ¶
type OperationType string