RecordMatch inserts a single match into the database. It is used to record the match between external and internal transactions during reconciliation. Parameters: - ctx: Context for managing request and tracing. - match: A pointer to the Match struct containing details of the external and internal t
(ctx context.Context, match *model.Match)
| 277 | // Returns: |
| 278 | // - An error if the operation fails, wrapped in an APIError for consistency. |
| 279 | func (d Datasource) RecordMatch(ctx context.Context, match *model.Match) error { |
| 280 | ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Saving match to db") |
| 281 | defer span.End() |
| 282 | |
| 283 | _, err := d.Conn.ExecContext(ctx, |
| 284 | `INSERT INTO ledgerforge.matches( |
| 285 | external_transaction_id, internal_transaction_id, reconciliation_id, amount, date |
| 286 | ) VALUES ($1, $2, $3, $4, $5)`, |
| 287 | match.ExternalTransactionID, match.InternalTransactionID, match.ReconciliationID, match.Amount, match.Date, |
| 288 | ) |
| 289 | if err != nil { |
| 290 | return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to record match", err) |
| 291 | } |
| 292 | |
| 293 | return nil |
| 294 | } |
| 295 | |
| 296 | // GetMatchesByReconciliationID retrieves all matches associated with a given reconciliation ID. |
| 297 | // It joins the matches table with external transactions to filter matches by reconciliation ID. |