UpdateMatchingRule updates an existing matching rule. It retrieves the existing rule, validates the new data, and then updates the rule. Parameters: - ctx: The context for managing the request. - rule: The updated rule data. Returns the updated rule, or an error if validation or update fails.
(ctx context.Context, rule model.MatchingRule)
| 1149 | // - rule: The updated rule data. |
| 1150 | // Returns the updated rule, or an error if validation or update fails. |
| 1151 | func (s *LedgerForge) UpdateMatchingRule(ctx context.Context, rule model.MatchingRule) (*model.MatchingRule, error) { |
| 1152 | // Retrieve the existing rule by its ID. |
| 1153 | existingRule, err := s.GetMatchingRule(ctx, rule.RuleID) |
| 1154 | if err != nil { |
| 1155 | return nil, err |
| 1156 | } |
| 1157 | |
| 1158 | // Preserve the original creation time and update the modified time. |
| 1159 | rule.CreatedAt = existingRule.CreatedAt |
| 1160 | rule.UpdatedAt = time.Now() |
| 1161 | |
| 1162 | // Validate the updated rule. |
| 1163 | err = s.validateRule(&rule) |
| 1164 | if err != nil { |
| 1165 | return nil, err |
| 1166 | } |
| 1167 | |
| 1168 | // Update the rule in the datasource. |
| 1169 | err = s.datasource.UpdateMatchingRule(ctx, &rule) |
| 1170 | if err != nil { |
| 1171 | return nil, err |
| 1172 | } |
| 1173 | |
| 1174 | return &rule, nil |
| 1175 | } |
| 1176 | |
| 1177 | // DeleteMatchingRule deletes a matching rule by its ID. |
| 1178 | // Parameters: |
nothing calls this directly
no test coverage detected