MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / GetMatchingRule

Method GetMatchingRule

database/reconciliation.go:568–600  ·  view source on GitHub ↗

GetMatchingRule retrieves a specific matching rule from the database by its rule ID. Parameters: - ctx: Context for managing the request and tracing. - id: The ID of the matching rule to be retrieved. Returns: - A pointer to the MatchingRule object if found, or an APIError if the operation fails.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

566// Returns:
567// - A pointer to the MatchingRule object if found, or an APIError if the operation fails.
568func (d Datasource) GetMatchingRule(ctx context.Context, id string) (*model.MatchingRule, error) {
569 ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Fetching matching rule")
570 defer span.End()
571
572 var rule model.MatchingRule
573 var criteriaJSON []byte
574
575 // Execute SQL query to retrieve the matching rule by rule_id
576 err := d.Conn.QueryRowContext(ctx, `
577 SELECT id, rule_id, created_at, updated_at, name, description, criteria
578 FROM ledgerforge.matching_rules
579 WHERE rule_id = $1
580 `, id).Scan(
581 &rule.ID, &rule.RuleID, &rule.CreatedAt, &rule.UpdatedAt,
582 &rule.Name, &rule.Description, &criteriaJSON,
583 )
584 if err != nil {
585 // Return NotFound error if no rows are returned
586 if err == sql.ErrNoRows {
587 return nil, apierror.NewAPIError(apierror.ErrNotFound, fmt.Sprintf("Matching rule with ID '%s' not found", id), err)
588 }
589 // Return InternalServer error for any other failure
590 return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to retrieve matching rule", err)
591 }
592
593 // Unmarshal JSON criteria into the MatchingRule object
594 err = json.Unmarshal(criteriaJSON, &rule.Criteria)
595 if err != nil {
596 return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to unmarshal matching rule criteria", err)
597 }
598
599 return &rule, nil
600}
601
602// GetExternalTransactionsPaginated retrieves external transactions based on the provided upload ID
603// with pagination. It first checks the cache, and if the data is not available, it fetches from the

Callers 2

Calls 2

NewAPIErrorFunction · 0.92
StartMethod · 0.45

Tested by 2