CreateMatchingRule creates a new matching rule after validating it. Parameters: - ctx: The context for managing the request. - rule: The matching rule to be created. Returns the created rule, or an error if validation or storage fails.
(ctx context.Context, rule model.MatchingRule)
| 1110 | // - rule: The matching rule to be created. |
| 1111 | // Returns the created rule, or an error if validation or storage fails. |
| 1112 | func (s *LedgerForge) CreateMatchingRule(ctx context.Context, rule model.MatchingRule) (*model.MatchingRule, error) { |
| 1113 | rule.RuleID = model.GenerateUUIDWithSuffix("rule") // Generate a unique rule ID. |
| 1114 | rule.CreatedAt = time.Now() |
| 1115 | rule.UpdatedAt = time.Now() |
| 1116 | |
| 1117 | // Validate the rule before storing it. |
| 1118 | err := s.validateRule(&rule) |
| 1119 | if err != nil { |
| 1120 | return nil, err |
| 1121 | } |
| 1122 | |
| 1123 | // Store the rule in the datasource. |
| 1124 | err = s.datasource.RecordMatchingRule(ctx, &rule) |
| 1125 | if err != nil { |
| 1126 | return nil, err |
| 1127 | } |
| 1128 | |
| 1129 | return &rule, nil |
| 1130 | } |
| 1131 | |
| 1132 | // GetMatchingRule retrieves a matching rule by its ID. |
| 1133 | // Parameters: |
nothing calls this directly
no test coverage detected