feat(api): add code filter to currency and sort option#4348
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds code-based filtering and a sortable ChangesCurrencies List Sorting and Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/currencies/models.go (1)
55-72:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winValidate
OrderalongsideOrderByinListCurrenciesInput.Validate().Right now invalid
Ordervalues can pass validation. Adding an explicit check keeps request handling deterministic and consistent withOrderBy.Suggested fix
func (i ListCurrenciesInput) Validate() error { var errs []error @@ if err := i.OrderBy.Validate(); err != nil { errs = append(errs, err) } + + switch i.Order { + case "", "asc", "desc": + // ok + default: + errs = append(errs, fmt.Errorf("invalid order: %s", i.Order)) + } return errors.Join(errs...) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/currencies/models.go` around lines 55 - 72, ListCurrenciesInput.Validate currently validates OrderBy but not Order, so invalid Order values can slip through; update ListCurrenciesInput.Validate to also validate the Order field (when non-nil) by calling its validation method (e.g., i.Order.Validate()) and appending any error to errs with context (for example fmt.Errorf("order: %w", err)), similarly to how FilterType and OrderBy are handled, then return errors.Join(errs...).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/v3/handlers/currencies/convert.go`:
- Around line 22-24: The check for unsupported operators on the currency code
uses a plain errors.New, causing inconsistent API error mapping; replace the
errors.New returned in the f.Neq != nil branch with the same validation error
helper used elsewhere (models.NewNillableGenericValidationError) so the API
returns a ValidationIssue—update the return inside the f.Neq check to call
models.NewNillableGenericValidationError with the appropriate field/key ("code")
and message stating only "eq" and "oeq" are supported to mirror other validation
branches.
---
Outside diff comments:
In `@openmeter/currencies/models.go`:
- Around line 55-72: ListCurrenciesInput.Validate currently validates OrderBy
but not Order, so invalid Order values can slip through; update
ListCurrenciesInput.Validate to also validate the Order field (when non-nil) by
calling its validation method (e.g., i.Order.Validate()) and appending any error
to errs with context (for example fmt.Errorf("order: %w", err)), similarly to
how FilterType and OrderBy are handled, then return errors.Join(errs...).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aa0e4a5e-c376-4689-9079-937ee15866e7
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (8)
api/spec/packages/aip/src/currencies/operations.tspapi/v3/api.gen.goapi/v3/handlers/currencies/convert.goapi/v3/handlers/currencies/list.goopenmeter/currencies/adapter/currencies.goopenmeter/currencies/models.goopenmeter/currencies/service/service.goopenmeter/currencies/service/service_test.go
d9f22d5 to
7da26b9
Compare
7da26b9 to
08df646
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/currencies/models.go (1)
52-53: ⚡ Quick winValidate
OrderinListCurrenciesInput.Validate()as well.Nice addition overall.
OrderByis validated, butOrder(Line 53) is currently unchecked in the same validator path (Line 75-77), which can let invalid sort direction values slip through from non-HTTP callers. Worth validating both fields together here.Also applies to: 75-77
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/currencies/models.go` around lines 52 - 53, The ListCurrenciesInput.Validate() currently checks OrderBy but not the Order field, so update the validator to validate Order as well (together with OrderBy) — within ListCurrenciesInput.Validate() verify that Order (type sortx.Order) is a valid sort direction and return an error if not; use the same validation approach/mechanism used for OrderBy (or a helper like sortx.ValidateOrder / existing enum checks) so invalid sort directions cannot be passed from non-HTTP callers, referencing the ListCurrenciesInput struct and its OrderBy and Order fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/filter/filter.go`:
- Around line 345-370: The likeMatch function mishandles SQL-style escapes (\,
\% \_ \\) because it treats every character independently; update the loop in
likeMatch to detect a backslash and look ahead (if i+1 < len(pattern)) and when
the next rune is '%', '_', or '\' treat that next character as a literal (emit
regexp.QuoteMeta for the next char) and advance i by 2; otherwise fall through
to the existing switch for '%' -> ".*", '_' -> '.', and default ->
regexp.QuoteMeta for the current character, preserving the (?i) fold prefix and
^/$ anchors and returning the final regexp.MatchString as before.
---
Nitpick comments:
In `@openmeter/currencies/models.go`:
- Around line 52-53: The ListCurrenciesInput.Validate() currently checks OrderBy
but not the Order field, so update the validator to validate Order as well
(together with OrderBy) — within ListCurrenciesInput.Validate() verify that
Order (type sortx.Order) is a valid sort direction and return an error if not;
use the same validation approach/mechanism used for OrderBy (or a helper like
sortx.ValidateOrder / existing enum checks) so invalid sort directions cannot be
passed from non-HTTP callers, referencing the ListCurrenciesInput struct and its
OrderBy and Order fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ddd74349-48b6-48b6-9e21-8418b235cd59
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (9)
api/spec/packages/aip/src/currencies/operations.tspapi/v3/api.gen.goapi/v3/handlers/currencies/list.goopenmeter/currencies/adapter/currencies.goopenmeter/currencies/models.goopenmeter/currencies/service/service.goopenmeter/currencies/service/service_test.gopkg/filter/filter.gopkg/filter/filter_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
- api/spec/packages/aip/src/currencies/operations.tsp
- api/v3/handlers/currencies/list.go
- openmeter/currencies/service/service.go
- openmeter/currencies/service/service_test.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/filter/filter.go`:
- Around line 322-339: The current f.And / f.Or handling short-circuits children
and can silently ignore ErrOperationNotSupported depending on child order;
change both branches to track unsupported-operation errors while still allowing
boolean short-circuiting: in And, iterate children calling child.matches, treat
non-ErrOperationNotSupported errors as before, if any child returns
ErrOperationNotSupported record that fact and continue, if any child returns
false immediately return false,nil, after loop return ErrOperationNotSupported
if recorded else true,nil; in Or, similarly record any ErrOperationNotSupported,
if any child returns true immediately return true,nil, after loop return
ErrOperationNotSupported if recorded else false,nil. Use the existing symbols
f.And, f.Or, child.matches and ErrOperationNotSupported to locate and implement
this logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c21e338d-ca54-4c67-9d3f-ef1f376c7392
📒 Files selected for processing (4)
openmeter/currencies/service/service.goopenmeter/currencies/service/service_test.gopkg/filter/filter.gopkg/filter/filter_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
- openmeter/currencies/service/service_test.go
- pkg/filter/filter_test.go
- openmeter/currencies/service/service.go
0c04da6 to
32f3ac6
Compare
32f3ac6 to
76a9f2a
Compare
Overview
Extend the
GET /api/v3/openmeter/currenciesendpoint with filter code and sort query params.Notes for review
List the currencies
curl --request GET \ --url 'http://localhost:8888/api/v3/openmeter/currencies?filter%5Bcode%5D%5Beq%5D=USD'Summary by CodeRabbit
New Features
Tests