fetchTransactions retrieves transactions for a balance within a specific time range using effective_date if available, otherwise falling back to created_at
(ctx context.Context, tx *sql.Tx, balanceID string, startTime, targetTime time.Time)
| 1492 | // fetchTransactions retrieves transactions for a balance within a specific time range |
| 1493 | // using effective_date if available, otherwise falling back to created_at |
| 1494 | func fetchTransactions(ctx context.Context, tx *sql.Tx, balanceID string, startTime, targetTime time.Time) (*sql.Rows, error) { |
| 1495 | logrus.WithFields(logrus.Fields{ |
| 1496 | "balance_id": balanceID, |
| 1497 | "start_time": startTime, |
| 1498 | "end_time": targetTime, |
| 1499 | }).Debug("querying transactions") |
| 1500 | rows, err := tx.QueryContext(ctx, ` |
| 1501 | SELECT precise_amount, source, destination, created_at, |
| 1502 | COALESCE(effective_date, created_at) as effective_date |
| 1503 | FROM ledgerforge.transactions |
| 1504 | WHERE (source = $1 OR destination = $1) |
| 1505 | AND COALESCE(effective_date, created_at) > $2 |
| 1506 | AND COALESCE(effective_date, created_at) <= $3 |
| 1507 | AND status = 'APPLIED' |
| 1508 | ORDER BY COALESCE(effective_date, created_at) ASC |
| 1509 | `, balanceID, startTime, targetTime) |
| 1510 | if err != nil { |
| 1511 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to get transactions", err) |
| 1512 | } |
| 1513 | |
| 1514 | return rows, nil |
| 1515 | } |
| 1516 | |
| 1517 | // applyTransaction applies a single transaction to update balance totals |
| 1518 | func applyTransaction(txn struct { |