GetReconciliation fetches a reconciliation record from the database based on its ID. Parameters: - ctx: Context for managing request and tracing. - id: The reconciliation ID to search for. Returns: - A pointer to the reconciliation record if found, or an error if not found or if a failure occurs.
(ctx context.Context, id string)
| 63 | // Returns: |
| 64 | // - A pointer to the reconciliation record if found, or an error if not found or if a failure occurs. |
| 65 | func (d Datasource) GetReconciliation(ctx context.Context, id string) (*model.Reconciliation, error) { |
| 66 | ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Fetching reconciliation from db") |
| 67 | defer span.End() |
| 68 | |
| 69 | rec := &model.Reconciliation{} |
| 70 | err := d.Conn.QueryRowContext(ctx, ` |
| 71 | SELECT id, reconciliation_id, upload_id, status, matched_transactions, |
| 72 | unmatched_transactions, started_at, completed_at |
| 73 | FROM ledgerforge.reconciliations |
| 74 | WHERE reconciliation_id = $1 |
| 75 | `, id).Scan( |
| 76 | &rec.ID, &rec.ReconciliationID, &rec.UploadID, &rec.Status, |
| 77 | &rec.MatchedTransactions, &rec.UnmatchedTransactions, |
| 78 | &rec.StartedAt, &rec.CompletedAt, |
| 79 | ) |
| 80 | if err != nil { |
| 81 | if err == sql.ErrNoRows { |
| 82 | return nil, apierror.NewAPIError(apierror.ErrNotFound, fmt.Sprintf("Reconciliation with ID '%s' not found", id), err) |
| 83 | } |
| 84 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to retrieve reconciliation", err) |
| 85 | } |
| 86 | |
| 87 | return rec, nil |
| 88 | } |
| 89 | |
| 90 | // UpdateReconciliationStatus updates the status, matched transactions, unmatched transactions, |
| 91 | // and completed_at timestamp of a reconciliation in the database. |