Documentation
¶
Index ¶
- Variables
- type Credit
- type Filter
- type Service
- func (s Service) Add(ctx context.Context, cred Credit) error
- func (s Service) Deduct(ctx context.Context, u usage.Usage) error
- func (s Service) GetBalance(ctx context.Context, accountID string) (int64, error)
- func (s Service) GetByID(ctx context.Context, id string) (Transaction, error)
- func (s Service) List(ctx context.Context, flt Filter) ([]Transaction, error)
- type Transaction
- type TransactionRepository
- type TransactionType
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("transaction not found") ErrInvalidUUID = errors.New("invalid syntax of uuid") ErrInvalidID = errors.New("invalid transaction id") ErrInvalidDetail = errors.New("invalid transaction detail") ErrNotEnough = errors.New("not enough credits") ErrAlreadyApplied = errors.New("credits already applied") // TxNamespaceUUID is the namespace for generating transaction UUIDs deterministically TxNamespaceUUID = uuid.MustParse("967416d0-716e-4308-b58f-2468ac14f20a") SourceSystemBuyEvent = "system.buy" SourceSystemOnboardEvent = "system.starter" )
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repository TransactionRepository) *Service
func (Service) GetBalance ¶
type Transaction ¶
type Transaction struct {
ID string
AccountID string
Amount int64
Type TransactionType
// Source is the source app or event that caused the transaction
Source string
Description string
// UserID is the user who initiated the transaction
UserID string
Metadata metadata.Metadata
CreatedAt time.Time
UpdatedAt time.Time
}
type TransactionRepository ¶
type TransactionRepository interface {
CreateEntry(ctx context.Context, debit, credit Transaction) ([]Transaction, error)
GetBalance(ctx context.Context, id string) (int64, error)
List(ctx context.Context, flt Filter) ([]Transaction, error)
GetByID(ctx context.Context, id string) (Transaction, error)
}
type TransactionType ¶
type TransactionType string
const ( TypeDebit TransactionType = "debit" TypeCredit TransactionType = "credit" )
Click to show internal directories.
Click to hide internal directories.