All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
There has been a cyclic dependency. transaction -> treasure_chest -> transaction_recurring -> transaction This has been temporarily solved by moving the GenerateTransactions function into the transaction package. In the future, this function has to be rewritten to use a proper Service insteas of direct DB access or replaced with a different system entirely.
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package transaction
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Transaction is at the center of the application.
|
|
//
|
|
// Every piece of data should be calculated based on transactions.
|
|
// This means potential calculation errors can be fixed later in time.
|
|
//
|
|
// If it becomes necessary to precalculate snapshots for performance reasons, this can be done in the future.
|
|
// But the transaction should always be the source of truth.
|
|
//
|
|
// There are the following constallations and their explanation:
|
|
//
|
|
// Account | TreasureChest | Value | Description
|
|
// --------|---------------|-------|----------------
|
|
// Y | Y | + | Invalid
|
|
// Y | Y | - | Expense
|
|
// Y | N | + | Deposit
|
|
// Y | N | - | Withdrawal (for moving between accounts)
|
|
// N | Y | + | Saving
|
|
// N | Y | - | Withdrawal (for moving between treasure chests)
|
|
// N | N | + | Invalid
|
|
// N | N | - | Invalid
|
|
type Transaction struct {
|
|
Id uuid.UUID `db:"id"`
|
|
UserId uuid.UUID `db:"user_id"`
|
|
|
|
Timestamp time.Time `db:"timestamp"`
|
|
Party string `db:"party"`
|
|
Description string `db:"description"`
|
|
|
|
AccountId *uuid.UUID `db:"account_id"`
|
|
TreasureChestId *uuid.UUID `db:"treasure_chest_id"`
|
|
Value int64 `db:"value"`
|
|
|
|
// If an error is present, then the transaction is not valid and should not be used for calculations.
|
|
Error *string `db:"error"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
// Either a user_id or a transaction_recurring_id
|
|
CreatedBy uuid.UUID `db:"created_by"`
|
|
UpdatedAt *time.Time `db:"updated_at"`
|
|
UpdatedBy *uuid.UUID `db:"updated_by"`
|
|
}
|
|
|
|
type TransactionItemsFilter struct {
|
|
AccountId string
|
|
TreasureChestId string
|
|
Error string
|
|
Page string
|
|
}
|