Skip to content

feat(creditgrant): add sorting to grant listing - #5376

Merged
turip merged 1 commit into
mainfrom
codex/credit-grant-sorting
Oct 27, 2026
Merged

turip merged 1 commit into
mainfrom
codex/credit-grant-sorting

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Credit grant listing currently has no explicit ordering. Add the existing AIP-style sort query parameter and default to created_at desc.

Supports created_at, updated_at, name, and id, with an optional asc or desc suffix. Sorting happens before pagination, with id breaking ties in the same direction. Invalid sort expressions return HTTP 400. Regenerated the v3 OpenAPI, server bindings, and Go/TypeScript SDKs.

Notes for reviewer

  • Supports one sort attribute, matching the shared parser used by other v3 list APIs. An explicit attribute without a direction sorts ascending.
  • PostgreSQL-backed tests cover every field in both directions and ties across one-item pages. The test harness uses the real void service to exercise an update time that differs from creation time.

Validation passed: HTTP handler and credit-grant service tests; PostgreSQL credit-grant and credit-purchase tests; Go SDK build/vet/tests; TypeScript typecheck and all 552 SDK tests; focused Go lint/style checks; git diff --check.

Full make gen-api is blocked by the legacy Python emitter's missing virtualenv. Affected v3 generation completed successfully.

Summary by CodeRabbit

  • New Features
    • Credit grant lists can now be sorted by creation time, update time, name, or ID, in ascending or descending order.
    • Sorting defaults to creation time, newest first. Ties are consistently broken by ID, and sorting is applied before pagination.
    • Invalid sort fields or directions return a bad-request error.
    • Updated API documentation describes the available sorting options.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Adds sorting to credit grant lists across the API, service, database query, and Go/TypeScript SDKs.

  • Credit grant lists can be sorted before their results are paged.

No actionable issues found. Tests were inspected, not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Client sort query] --> B{Parse and check field}
  B -->|Invalid| C[HTTP 400]
  B -->|Valid or omitted| D[Grant service]
  D --> E[Apply filters]
  E --> F[Sort with ID tie-break]
  F --> G[Apply pagination]
  G --> H[Return grants]
Loading

Reviews (1) · Last reviewed commit: "feat(creditgrant): add sorting to grant ..." · Reviewed by Greptile

@GAlexIHU
GAlexIHU requested a review from a team as a code owner October 27, 2026 10:58
@GAlexIHU GAlexIHU added the release-note/feature Release note: Exciting New Features label Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5e0d2a9 and ed0718b.

Files ignored due to path filters: 1
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
Files selected for processing: 14
  • api/spec/packages/aip-client-javascript/src/funcs/customers.ts
  • api/spec/packages/aip-client-javascript/src/models/operations/customers.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/v3/api.gen.go
  • api/v3/client/customers_credits_grants.go
  • api/v3/handlers/customers/credits/list_grants.go
  • api/v3/handlers/customers/credits/list_grants_test.go
  • openmeter/billing/charges/README.md
  • openmeter/billing/charges/creditpurchase/adapter.go
  • openmeter/billing/charges/creditpurchase/adapter/charge.go
  • openmeter/billing/creditgrant/service.go
  • openmeter/billing/creditgrant/service/service.go
  • test/credits/creditgrant_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

Credit-grant listing now accepts an optional sort parameter. The handler validates and forwards sort values, and the listing adapter orders results before pagination. The API specifications, generated clients, tests, and README document or cover the sorting behavior.

Changes: Credit grant sorting

Layer / File(s) Summary
Sort query contract and transport
api/spec/packages/aip/..., api/spec/packages/aip-client-javascript/src/..., api/v3/api.gen.go, api/v3/client/customers_credits_grants.go
The API specification and generated models add the optional sort parameter. The JavaScript and Go clients encode it in list requests.
Parse, validate, and forward sort values
api/v3/handlers/customers/credits/list_grants.go, api/v3/handlers/customers/credits/list_grants_test.go, openmeter/billing/creditgrant/service.go, openmeter/billing/creditgrant/service/service.go
The handler defaults to created_at descending, parses supplied values, and rejects invalid or unsupported sorts. The credit-grant service validates and forwards the sort key and direction. Endpoint tests cover default, valid, and invalid sort values.
Order results and verify pagination
openmeter/billing/charges/creditpurchase/adapter.go, openmeter/billing/charges/creditpurchase/adapter/charge.go, test/credits/creditgrant_test.go, openmeter/billing/charges/README.md
The charge-listing adapter validates sort keys and directions, then orders results before pagination. Integration tests cover default and explicit sorting across pages. The README documents the default order and ID tie-break behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant ListCreditGrantsHandler
  participant CreditGrantService
  participant CreditPurchaseService
  APIClient->>ListCreditGrantsHandler: Sends sort query
  ListCreditGrantsHandler->>CreditGrantService: Passes OrderBy and Order
  CreditGrantService->>CreditPurchaseService: Forwards OrderBy and Order
  CreditPurchaseService->>CreditPurchaseService: Orders results before pagination
Loading

Suggested reviewers: turip, tothandras, borosr

Merge Risk: Minimal · up to ed071

Credit-grant sorting appears ready to merge after normal checks; no material issue was identified.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding sorting to credit grant listing.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@turip
turip merged commit 65104fd into main Oct 27, 2026
37 of 39 checks passed
@turip
turip deleted the codex/credit-grant-sorting branch October 27, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants