transactions

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSuggestionLimit = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountSvc added in v0.2.0

type AccountSvc interface {
	GetAllAccounts(ctx context.Context) ([]*database.Account, error)
	GetDefaultAccount(ctx context.Context, accountType v1.AccountType) (*database.Account, error)
}

type BaseAmountService

type BaseAmountService struct {
	// contains filtered or unexported fields
}

func NewBaseAmountService

func NewBaseAmountService(
	baseCurrency string,
) *BaseAmountService

func (*BaseAmountService) RecalculateAmountInBaseCurrency

func (s *BaseAmountService) RecalculateAmountInBaseCurrency(
	_ context.Context,
	tx *gorm.DB,
	specificTxIDs []*database.Transaction,
) error

func (*BaseAmountService) RecalculateAmountInBaseCurrencyForAll

func (s *BaseAmountService) RecalculateAmountInBaseCurrencyForAll(
	ctx context.Context,
	tx *gorm.DB,
) error

type BaseAmountSvc

type BaseAmountSvc interface {
	RecalculateAmountInBaseCurrency(
		_ context.Context,
		tx *gorm.DB,
		txs []*database.Transaction,
	) error
}

type BulkRequest

type BulkRequest struct {
	OriginalTx *database.Transaction // for update
	Req        *transactionsv1.CreateTransactionRequest
}

type CalculateDailyStatRequest

type CalculateDailyStatRequest struct {
	StartDate time.Time
	AccountID int32
}

type CategoryAssignment added in v0.3.1

type CategoryAssignment struct {
	TransactionID int64
	CategoryID    *int32 // nil clears the category
}

type CurrencyConverterSvc

type CurrencyConverterSvc interface {
	Convert(
		ctx context.Context,
		fromCurrency string,
		toCurrency string,
		amount decimal.Decimal,
	) (decimal.Decimal, error)
}

type DoubleEntrySvc added in v0.2.0

type DoubleEntrySvc interface {
	Record(
		ctx context.Context,
		dbTx *gorm.DB,
		txs []*database.Transaction,
		accounts map[int32]*database.Account,
	) error

	DeleteByTransactionIDs(
		_ context.Context,
		dbTx *gorm.DB,
		txIds []int64,
	) error
}

type FillResponse added in v0.2.0

type FillResponse struct {
	Accounts map[int32]*database.Account
}

type HistorySvc added in v1.2.0

type HistorySvc interface {
	Record(ctx context.Context, tx *gorm.DB, req history.RecordRequest) error
}

type LockerSvc

type LockerSvc interface {
	LockDailyStat(ctx context.Context, dbTx *gorm.DB) error
	LockMonthlyStat(ctx context.Context, dbTx *gorm.DB) error
}

type MapperSvc

type MapperSvc interface {
	MapTransaction(ctx context.Context, tx *database.Transaction) *v1.Transaction
}

type RuleSvc

type RuleSvc interface {
	ProcessTransactions(
		ctx context.Context,
		inputTxs []*database.Transaction,
	) ([]*database.Transaction, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(
	cfg *ServiceConfig,
) *Service

func (*Service) BulkSetCategory added in v0.3.1

func (s *Service) BulkSetCategory(
	ctx context.Context,
	assignments []CategoryAssignment,
) error

func (*Service) BulkSetTags added in v0.3.1

func (s *Service) BulkSetTags(
	ctx context.Context,
	assignments []TagsAssignment,
) error

func (*Service) ConvertRequestToTransaction added in v0.2.9

func (s *Service) ConvertRequestToTransaction(
	ctx context.Context,
	req *transactionsv1.CreateTransactionRequest,
	originalTx *database.Transaction,
) (*database.Transaction, error)

ConvertRequestToTransaction converts a CreateTransactionRequest to a database.Transaction

func (*Service) CreateBulkInternal

func (s *Service) CreateBulkInternal(
	ctx context.Context,
	reqs []*BulkRequest,
	tx *gorm.DB,
	opts UpsertOptions,
) ([]*transactionsv1.CreateTransactionResponse, error)

func (*Service) CreateRawTransaction added in v0.1.1

func (s *Service) CreateRawTransaction(
	ctx context.Context,
	newTx *database.Transaction,
) (*transactionsv1.CreateTransactionResponse, error)

func (*Service) DeleteTransaction added in v0.2.9

func (*Service) FillDeposit added in v0.2.0

func (s *Service) FillDeposit(
	_ context.Context,
	req *transactionsv1.Income,
	newTx *database.Transaction,
) (*FillResponse, error)

func (*Service) FillWithdrawal added in v0.2.0

func (s *Service) FillWithdrawal(
	_ context.Context,
	req *transactionsv1.Expense,
	newTx *database.Transaction,
) (*FillResponse, error)

func (*Service) FinalizeTransactions added in v0.1.1

func (s *Service) FinalizeTransactions(
	ctx context.Context,
	tx *gorm.DB,
	created []*database.Transaction,
	originalTxs []*database.Transaction,
	opts UpsertOptions,
) ([]*transactionsv1.CreateTransactionResponse, error)

func (*Service) GetTitleSuggestions added in v0.2.7

func (*Service) GetTransactionByIDs

func (s *Service) GetTransactionByIDs(ctx context.Context, ids []int64) ([]*database.Transaction, error)

func (*Service) StoreStat added in v0.2.0

func (s *Service) StoreStat(
	ctx context.Context,
	tx *gorm.DB,
	created []*database.Transaction,
	originalTxs []*database.Transaction,
	accountMap map[int32]*database.Account,
) error

type ServiceConfig

type ServiceConfig struct {
	StatsSvc             StatsSvc
	MapperSvc            MapperSvc
	CurrencyConverterSvc CurrencyConverterSvc
	BaseAmountService    BaseAmountSvc
	RuleSvc              RuleSvc
	ValidationSvc        ValidationSvc
	DoubleEntry          DoubleEntrySvc
	AccountSvc           AccountSvc
	HistorySvc           HistorySvc
}

type StatService

type StatService struct {
	// contains filtered or unexported fields
}

func NewStatService

func NewStatService() *StatService

func (*StatService) BuildImpactedAccounts

func (s *StatService) BuildImpactedAccounts(newTxs []*database.Transaction) map[int32]time.Time

func (*StatService) CalculateDailyStat

func (s *StatService) CalculateDailyStat(
	_ context.Context,
	dbTx *gorm.DB,
	req CalculateDailyStatRequest,
) error

func (*StatService) HandleTransactions

func (s *StatService) HandleTransactions(
	ctx context.Context,
	dbTx *gorm.DB,
	newTxs []*database.Transaction,
) error

type StatsSvc

type StatsSvc interface {
	HandleTransactions(
		ctx context.Context,
		dbTx *gorm.DB,
		newTxs []*database.Transaction,
	) error
}

type TagsAssignment added in v0.3.1

type TagsAssignment struct {
	TransactionID int64
	TagIDs        []int32 // nil or empty clears all tags
}

type UpsertOptions added in v0.2.0

type UpsertOptions struct {
	SkipAccountSourceDestValidation bool
	SkipValidationErrors            bool
}

type ValidationSvc added in v0.2.0

type ValidationSvc interface {
	Validate(
		ctx context.Context,
		dbTx *gorm.DB,
		req *validation.Request,
	) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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