feat: add filter and sort to apps#4372
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:
📝 WalkthroughWalkthroughAdds API-level filtering and sorting to the apps list endpoint and wires it through spec, handler, domain types, adapters, integrations, and tests. ChangesApps List Filtering & Sorting
Sequence Diagram(s)sequenceDiagram
participant Client
participant HTTPHandler
participant Filters
participant AppService
participant AppAdapter
participant Database
Client->>HTTPHandler: GET /apps?sort=...&filter[...]
HTTPHandler->>Filters: parse filter[...] / sort
Filters-->>HTTPHandler: parsed filter values or error
HTTPHandler->>AppService: ListAppsRequest (filters, order)
AppService->>AppAdapter: ListAppsRequest
AppAdapter->>AppAdapter: apply filter.ApplyToQuery / compute order
AppAdapter->>Database: SQL query (WHERE, ORDER BY)
Database-->>AppAdapter: rows
AppAdapter-->>AppService: mapped results
AppService-->>HTTPHandler: List response
HTTPHandler-->>Client: 200 or BadRequest
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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)
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: 3
🤖 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/spec/packages/aip/src/apps/operations.tsp`:
- Around line 58-59: Update the filter example in the JSDoc block in
apps/operations.tsp to use the deep-object operator form instead of a plain
value; replace the current example `filter[name]=my-app` with
`filter[name][eq]=my-app` (or equivalent operator such as [contains], [ne],
etc.) so it matches the declared deep-object filter format used by the
implementation and clearly shows operator fields.
In `@openmeter/app/adapter/app.go`:
- Around line 122-126: The created_at ordering branch (case
app.AppOrderByCreatedAt in app.go) needs a stable tie-breaker so pagination is
deterministic: when applying query.Order(appdb.ByCreatedAt(order...)) also order
by a unique stable column (e.g., the primary key `id` or `uuid`) as a secondary
sort. Implement this by either extending appdb.ByCreatedAt to include the id as
a tie-breaker or by chaining another Order call (e.g., query =
query.Order(appdb.ByCreatedAt(order...)).Order(appdb.ByID(order...)) or
equivalent) so rows with equal created_at are consistently ordered.
In `@openmeter/app/service/list_test.go`:
- Line 217: The test uses require.Equal inside the assert.Eventually retry
closure which calls FailNow and breaks the retry loop; update the tests that use
assert.Eventually (the closure that checks result.TotalCount and similar
assertions) to remove any require.* calls from inside the closure, instead
return the boolean condition from the closure and then call require.Equal (or
other require.*) on result.TotalCount and the other expectations after
assert.Eventually returns true; look for usages of assert.Eventually,
require.Equal, and the result variable in this file (the assertions referencing
result.TotalCount and similar) and move the require checks out of the closure
into the code that runs after the eventual wait succeeds.
🪄 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: e85f4b45-dbe4-493f-8ae5-f0459ff2af3c
⛔ 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/apps/operations.tspapi/v3/api.gen.goapi/v3/handlers/apps/list_app.goopenmeter/app/adapter/app.goopenmeter/app/adapter/customer.goopenmeter/app/app.goopenmeter/app/sandbox/helpers.goopenmeter/app/service/list_test.goopenmeter/billing/service/profile.go
f2860bf to
8eb6b89
Compare
8eb6b89 to
4f63c41
Compare
4f63c41 to
f40044b
Compare
f40044b to
ab50e0c
Compare
Add filters and sorting to the List App endpoint
What
Adds
filter[*]query parameters and asortquery parameter toGET /api/v3/openmeter/apps.Supported filters:
id,name,type,status.Supported sort fields:
id,created_at (default)with optionalasc/descsuffix.Why
Callers need a way to narrow down app results without client-side filtering, e.g. finding all apps for a given type or sorted by creation time.
How
ListAppsParamsFilterand wiredsort/filterquery params intolistListAppsRequestTesting
Filter by app type:
curl -s "http://localhost:8888/api/v3/openmeter/apps?sort=created_at%20asc&filter%5Btype%5D%5Beq%5D=sandbox"Sort by creation date descending:
curl -s "http://localhost:8888/api/v3/openmeter/apps?sort=created_at%20asc"Summary by CodeRabbit
New Features
Improvements
Tests