Skip to content

feat(currencies): add custom currency update endpoint - #4922

Open
borbelyr-kong wants to merge 4 commits into
mainfrom
feat/currencies-update-custom-currency
Open

feat(currencies): add custom currency update endpoint#4922
borbelyr-kong wants to merge 4 commits into
mainfrom
feat/currencies-update-custom-currency

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What

Adds PUT /api/v3/openmeter/currencies/custom/{currencyId} (update-custom-currency) so users can edit a custom currency's presentational attributes: name, symbol, decimal mark and thousand separator. Custom currencies were previously create/read-only.

Why

Users who typo a currency's name or want to change how amounts are formatted currently have no way to fix it — the only workaround is creating a replacement currency, which is not viable once charges or plans reference the original. code and precision stay immutable, and are absent from the request model rather than merely rejected. Charges, invoices and ledger currency dimensions are denominated with them, and CurrencyReference.MarshalText snapshots the precision into persisted ledger references — editing either would misstate historical monetary records.

How

  • TypeSpec (api/spec/packages/aip/src/currencies/): new CurrencyCustomUpdate model plus a @put operation on the existing CurrenciesCustomOperations interface. A dedicated request model (rather than Shared.UpdateRequest<CurrencyCustom>) keeps the immutable fields unrepresentable and leaves the shared
    CurrencyBase visibility untouched — the generated diff is additive only.
  • Domain (openmeter/currencies/): UpdateCurrencyInput with Validate(), threaded through the service and repository interfaces.
  • Adapter: a single ent UpdateOneID scoped by namespace and DeletedAtIsNil(); not-found maps to 404. No read-then-merge is needed because the request carries every mutable attribute.
  • Handler (api/v3/handlers/currencies/update.go): sits behind the same creditsEnabled gate as create, and uses apierrors.GenericErrorEncoder().
  • Regenerated OpenAPI spec, Go server, and Go/JS SDKs.

Summary by CodeRabbit

  • New Features

    • Added API and Go/JavaScript SDK support for updating custom currency presentation settings.
    • Name, symbol, decimal mark, and thousand separator can be changed.
    • Currency code and precision remain unchanged.
    • Custom currency symbols can be cleared by omitting them.
  • Bug Fixes

    • Added validation for required fields, separator formatting, and invalid updates.
  • Documentation

    • Added documentation for the custom currency update operation.

Greptile Summary

The PR adds a namespace-scoped PUT endpoint for replacing a custom currency’s mutable presentation attributes while preserving its code and precision.

  • Adds the TypeSpec operation and regenerated OpenAPI, Go, and JavaScript SDK surfaces.
  • Adds handler, service, repository, and Ent adapter support for validated updates.
  • Adds service and end-to-end coverage for replacement semantics, immutable fields, symbol clearing, separator validation, and feature gating.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
api/spec/packages/aip/src/currencies/operations.tsp Defines the new private, internal, unstable PUT operation using an update-visible request projection.
api/v3/handlers/currencies/update.go Parses and maps the replacement request, applies the existing custom-currency feature gate, and returns the converted currency.
openmeter/currencies/service.go Introduces a validated update input containing only mutable presentation attributes.
openmeter/currencies/service/service.go Validates update input and delegates persistence through the existing transaction boundary.
openmeter/currencies/adapter/currencies.go Updates only mutable fields while enforcing namespace and soft-deletion predicates and mapping non-matches to not found.
e2e/currencies_v3_test.go Covers successful replacement, immutable-field preservation, symbol clearing, and invalid update rejection.

Sequence Diagram

sequenceDiagram
  participant Client
  participant API as V3 API
  participant Handler as Currency Handler
  participant Service as Currency Service
  participant DB as Ent/PostgreSQL
  Client->>API: "PUT /currencies/custom/{currencyId}"
  API->>API: Validate request against OpenAPI
  API->>Handler: Dispatch with namespace and currency ID
  Handler->>Service: UpdateCurrency(input)
  Service->>Service: Validate mutable attributes
  Service->>DB: Update ID scoped by namespace and deleted_at IS NULL
  DB-->>Service: Updated custom currency
  Service-->>Handler: Currency
  Handler-->>Client: 200 BillingCurrencyCustom
Loading

Reviews (7): Last reviewed commit: "refactor(currencies): remove unnecessary..." | Re-trigger Greptile

Context used:

@borbelyr-kong
borbelyr-kong requested a review from a team as a code owner August 12, 2026 15:34
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5dcd12c9-4a39-44eb-8bc4-cb5cc08ba887

📥 Commits

Reviewing files that changed from the base of the PR and between c9d6cbb and 7639a20.

📒 Files selected for processing (1)
  • openmeter/currencies/adapter/currencies.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/currencies/adapter/currencies.go

📝 Walkthrough

Walkthrough

The PR adds custom currency update support through a PUT endpoint. It defines update models and validation, updates currency service and persistence layers, exposes Go and JavaScript client methods, wires the HTTP route, and adds service and end-to-end tests.

Changes

Custom currency update

Layer / File(s) Summary
API contracts and schemas
api/spec/packages/aip/src/currencies/*.tsp, api/spec/packages/aip-client-javascript/src/models/schemas.ts, api/v3/api.gen.go
The API defines the PUT operation and mutable presentation fields. JSON and wire schemas validate update bodies and exclude code and precision. Generated route bindings and the embedded OpenAPI specification include the endpoint.
Currency service and persistence
openmeter/currencies/service.go, openmeter/currencies/service/service.go, openmeter/currencies/repository.go, openmeter/currencies/adapter/currencies.go, openmeter/currencies/service/service_test.go, openmeter/server/server_test.go
The service validates namespaced update input. The adapter updates mutable fields transactionally and handles namespaces, deleted records, and not-found errors. Tests cover replacement, symbol clearing, validation, immutable fields, and missing currencies.
HTTP API and Go client
api/v3/handlers/currencies/*, api/v3/server/routes.go, api/v3/client/*, e2e/currencies_v3_test.go
The v3 route and handler invoke the currency service. The Go client sends and decodes update requests. Tests cover successful updates and invalid input.
JavaScript SDK operation
api/spec/packages/aip-client-javascript/src/{models,funcs,sdk}/*, api/spec/packages/aip-client-javascript/src/index.ts, api/spec/packages/aip-client-javascript/README.md
The SDK adds update request and response types, validates and sends the PUT request, exposes InternalCurrencies.updateCustomCurrency, exports the model, and documents the operation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Mergeability Score: ⚪ Minimal · up to 7639a

This change adds editing for custom currency presentation fields without supplied evidence of a current correctness or production risk; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant GoClient
  participant Server
  participant UpdateCurrencyHandler
  participant CurrencyService
  participant CurrencyRepository
  GoClient->>Server: PUT custom currency update
  Server->>UpdateCurrencyHandler: Forward currency ID and request
  UpdateCurrencyHandler->>CurrencyService: UpdateCurrency with namespaced input
  CurrencyService->>CurrencyRepository: Update mutable presentation fields
  CurrencyRepository-->>CurrencyService: Return updated currency
  CurrencyService-->>UpdateCurrencyHandler: Return updated currency
  UpdateCurrencyHandler-->>Server: Encode HTTP 200 JSON response
  Server-->>GoClient: Return CurrencyCustom response
Loading

Possibly related PRs

Suggested labels: area/billing

Suggested reviewers: mark-vass-konghq, chrisgacsal

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
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 a custom currency update endpoint.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/currencies-update-custom-currency

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.

@borbelyr-kong borbelyr-kong added the release-note/misc Miscellaneous changes label Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
api/v3/handlers/currencies/update.go (1)

27-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move the non-trivial callbacks into named methods.

These callbacks contain meaningful validation, domain translation, persistence, and error mapping. Keep the transaction and transport callbacks small. Delegate the work to named methods.

  • api/v3/handlers/currencies/update.go#L27-L61: Extract request parsing and service-response mapping into named handler methods.
  • openmeter/currencies/adapter/currencies.go#L222-L245: Extract the Ent update and DB error mapping into a named adapter method.

As per coding guidelines, “Do not hide type switching, validation, persistence mapping, or meaningful domain translation inside local closures; use named helpers and reserve inline callbacks for obvious, tiny logic.”

🤖 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 `@api/v3/handlers/currencies/update.go` around lines 27 - 61, Extract the
non-trivial transport callbacks in api/v3/handlers/currencies/update.go lines
27-61 into named handler methods: move request validation, namespace resolution,
body parsing, and UpdateCurrencyRequest construction into one method, and move
service response mapping into another, leaving only small delegating callbacks.
In openmeter/currencies/adapter/currencies.go lines 222-245, extract the Ent
update and database error mapping into a named adapter method, keeping the
surrounding transaction callback as a thin delegate.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@api/v3/handlers/currencies/update.go`:
- Around line 27-61: Extract the non-trivial transport callbacks in
api/v3/handlers/currencies/update.go lines 27-61 into named handler methods:
move request validation, namespace resolution, body parsing, and
UpdateCurrencyRequest construction into one method, and move service response
mapping into another, leaving only small delegating callbacks. In
openmeter/currencies/adapter/currencies.go lines 222-245, extract the Ent update
and database error mapping into a named adapter method, keeping the surrounding
transaction callback as a thin delegate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ec02233-6bb8-4a7f-a0cb-83827fbd38d9

📥 Commits

Reviewing files that changed from the base of the PR and between 2064f94 and 14a28ea.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (24)
  • api/spec/packages/aip-client-javascript/README.md
  • api/spec/packages/aip-client-javascript/src/funcs/currencies.ts
  • api/spec/packages/aip-client-javascript/src/index.ts
  • api/spec/packages/aip-client-javascript/src/models/operations/currencies.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/models/types.ts
  • api/spec/packages/aip-client-javascript/src/sdk/internal.ts
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/currencies/operations.tsp
  • api/v3/api.gen.go
  • api/v3/client/README.md
  • api/v3/client/currencies.go
  • api/v3/client/models_currencies.go
  • api/v3/handlers/currencies/handler.go
  • api/v3/handlers/currencies/handler_test.go
  • api/v3/handlers/currencies/update.go
  • api/v3/server/routes.go
  • e2e/currencies_v3_test.go
  • openmeter/currencies/adapter/currencies.go
  • openmeter/currencies/repository.go
  • openmeter/currencies/service.go
  • openmeter/currencies/service/service.go
  • openmeter/currencies/service/service_test.go
  • openmeter/server/server_test.go

@borbelyr-kong
borbelyr-kong force-pushed the feat/currencies-update-custom-currency branch 3 times, most recently from c36c5f3 to 7639a20 Compare August 13, 2026 20:21
@borbelyr-kong borbelyr-kong added kind/feature New feature or request release-note/feature Release note: Exciting New Features area/product-catalog and removed release-note/misc Miscellaneous changes labels Aug 13, 2026
@borbelyr-kong
borbelyr-kong force-pushed the feat/currencies-update-custom-currency branch from 7639a20 to 4cdf9b0 Compare August 14, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/product-catalog kind/feature New feature or request release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants