Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountRepository ¶
type AccountRepository interface {
Get(id uuid.UUID) (*account.Account, error)
Create(account *account.Account) error
Update(account *account.Account) error
Delete(id uuid.UUID) error
}
AccountRepository defines the interface for account data access operations.
type TransactionRepository ¶
type TransactionRepository interface {
Create(transaction *account.Transaction, convInfo *common.ConversionInfo,
maskedExternalTarget string) error
Get(id uuid.UUID) (*account.Transaction, error)
List(userID, accountID uuid.UUID) ([]*account.Transaction, error)
// GetByPaymentID returns a transaction by its payment provider ID.
GetByPaymentID(paymentID string) (*account.Transaction, error)
Update(tx *account.Transaction) error
}
TransactionRepository defines the interface for transaction data access operations.
type UnitOfWork ¶
type UnitOfWork interface {
// Do executes the given function within a transaction boundary.
// The provided function receives a UnitOfWork for repository access.
// If the function returns an error, the transaction is rolled back.
Do(ctx context.Context, fn func(uow UnitOfWork) error) error
// GetRepository returns a repository of the requested type, bound to the
// current transaction/session. This method is maintained for backward
// compatibility but is deprecated in favor of type-safe methods.
// Example:
// repoAny, err := uow.GetRepository((*UserRepository)(nil))
// repo := repoAny.(UserRepository)
GetRepository(repoType any) (any, error)
// Type-safe repository access methods (preferred approach)
AccountRepository() (AccountRepository, error)
TransactionRepository() (TransactionRepository, error)
UserRepository() (UserRepository, error)
}
UnitOfWork defines the contract for transactional work and type-safe repository access.
Why is GetRepository part of UnitOfWork? - Ensures all repositories use the same DB session/transaction for true atomicity. - Keeps service code clean and focused on business logic. - Centralizes repository wiring and registry for maintainability. - Prevents accidental use of the wrong DB session (which would break transactionality). - Is idiomatic for Go UoW patterns and easy to mock in tests.
Do runs the given function in a transaction boundary, providing a UnitOfWork for repository access. GetRepository provides type-safe access to repositories using the transaction session. Example usage:
repoAny, err := uow.GetRepository((*UserRepository)(nil)) repo := repoAny.(UserRepository)
type UserRepository ¶
type UserRepository interface {
Get(id uuid.UUID) (*user.User, error)
GetByUsername(username string) (*user.User, error)
GetByEmail(email string) (*user.User, error)
Valid(id uuid.UUID, password string) bool
Create(user *user.User) error
Update(user *user.User) error
Delete(id uuid.UUID) error
}
UserRepository defines the interface for user data access operations.