Skip to content

feat: add expand option to currency list api - #4771

Merged
chrisgacsal merged 2 commits into
mainfrom
feat/currencies-list
Jul 22, 2026
Merged

feat: add expand option to currency list api#4771
chrisgacsal merged 2 commits into
mainfrom
feat/currencies-list

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Overview

Add expand options to list currencies service API.

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • New Features

    • Currency listings can now optionally include the currently effective cost basis.
    • Batch currency resolution now requests cost-basis expansion to keep results consistent.
  • Bug Fixes

    • Cost-basis records are now filtered by time, preventing expired or not-yet-effective entries from appearing.
    • Cost basis is correctly resolved at the time a custom currency was deleted.
    • When listing fiat currencies, cost-basis information remains unset as expected.
  • Tests

    • Added coverage for custom currency cost-basis expansion (including deletion-time scenarios).

Greptile Summary

This PR adds cost-basis expansion to currency listing and resolution. The main changes are:

  • Adds an expansion option to the currency list input.
  • Loads effective cost bases for custom currencies.
  • Requests cost bases during batch currency resolution.
  • Adds tests for live, fiat, and deleted currencies.

Confidence Score: 4/5

The deleted-currency query should be corrected before merging.

  • The application clock is now used consistently.
  • Deleted currencies are evaluated at their deletion time.
  • A valid historical cost basis can still be omitted when parent and child deletion timestamps differ.

openmeter/currencies/adapter/currencies.go

Important Files Changed

Filename Overview
openmeter/currencies/adapter/currencies.go Adds shared cost-basis expansion, but deleted currencies can lose an active basis when deletion timestamps differ.
openmeter/currencies/currencyresolver/resolver.go Requests cost-basis expansion during batch currency resolution.
openmeter/currencies/service.go Adds currency expansion options to list requests.
openmeter/currencies/service/service_test.go Adds expansion coverage, including a deleted-currency case with matching deletion timestamps.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
openmeter/currencies/adapter/currencies.go:381
**Deletion timestamps must match**

This predicate requires a cost basis and its currency to have identical `deleted_at` values. Cost bases are created with `deleted_at = NULL`, and the schema does not synchronize that field when the currency is deleted. When a basis was active at the currency's deletion time but remains undeleted or was deleted separately, expansion returns an empty cost basis. The query should select records that were active at the currency's deletion time without requiring matching deletion timestamps.

Reviews (3): Last reviewed commit: "refactor: sideloading costbasis for curr..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@chrisgacsal chrisgacsal self-assigned this Jul 22, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner July 22, 2026 13:56
@chrisgacsal chrisgacsal added the release-note/misc Miscellaneous changes label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Currency listing and retrieval now support time-filtered cost-basis expansion. Batch resolution requests the expansion, custom currency queries apply shared effective-time filtering, and service tests cover active, fiat, and deleted currency results.

Changes

Currency cost-basis expansion

Layer / File(s) Summary
Cost-basis expansion request wiring
openmeter/currencies/service.go, openmeter/currencies/currencyresolver/resolver.go
ListCurrenciesInput exposes expansion options, and batch resolution enables cost-basis expansion.
Filtered cost-basis query integration
openmeter/currencies/adapter/currencies.go
Listing and retrieval use WithCostBasis to scope history by effective time and deletion state.
Cost-basis expansion validation
openmeter/currencies/service/service_test.go
Tests verify active custom-currency cost basis, nil fiat expansion, and deletion-time filtering.

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

Sequence Diagram(s)

sequenceDiagram
  participant BatchResolveCurrencies
  participant CurrencyService
  participant CustomCurrencyAdapter
  participant CostBasisHistory
  BatchResolveCurrencies->>CurrencyService: request CostBasis expansion
  CurrencyService->>CustomCurrencyAdapter: list currencies
  CustomCurrencyAdapter->>CostBasisHistory: apply WithCostBasis
  CostBasisHistory-->>CustomCurrencyAdapter: return effective records
Loading

Possibly related PRs

Suggested labels: release-note/feature

Suggested reviewers: mark-vass-konghq, borbelyr-kong, turip

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 matches the main change: adding expansion options to the currency list API.
✨ 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-list

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.

Comment thread openmeter/currencies/service.go
Comment thread openmeter/currencies/adapter/currencies.go Outdated
Comment thread openmeter/currencies/adapter/currencies.go Outdated

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

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 `@openmeter/currencies/service/service_test.go`:
- Around line 193-257: Add future-dated and expired cost-basis fixtures in the
ListWithCostBasis test before calling ListCurrencies. Configure them for the
custom currency, then assert the expanded CostBasis contains only the currently
effective entry, preserving the existing fiat assertions and expected counts.
🪄 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: ce9ebfec-7ac9-4435-9c4f-5a81cc502e33

📥 Commits

Reviewing files that changed from the base of the PR and between b368460 and 5083276.

📒 Files selected for processing (4)
  • openmeter/currencies/adapter/currencies.go
  • openmeter/currencies/currencyresolver/resolver.go
  • openmeter/currencies/service.go
  • openmeter/currencies/service/service_test.go

Comment thread openmeter/currencies/service/service_test.go

@gergely-kurucz-konghq gergely-kurucz-konghq 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.

LGTM! Small nit comment, consider if it makes sense.

Comment thread openmeter/currencies/adapter/currencies.go Outdated

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

Actionable comments posted: 2

🤖 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 `@openmeter/currencies/adapter/currencies.go`:
- Around line 171-176: Capture the return value of WithCostBasis at both call
sites in the currency query flow, including the branches using now and at, by
reassigning the returned query back to q before continuing. Do not rely on
in-place mutation of the Ent builder; preserve the existing conditional
eager-loading behavior.
- Around line 370-397: Update the non-null customcurrency.deleted_at branch in
WithCostBasis to also enforce the cost-basis effective window: effective_from
must be at or before at, and effective_to must be null or after at. Preserve its
existing deletion-timestamp equality condition and keep the active-currency
branch unchanged.
🪄 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: 9b73203e-4d69-4f2e-96dc-96d67bc1c308

📥 Commits

Reviewing files that changed from the base of the PR and between 5083276 and fc01e09.

📒 Files selected for processing (1)
  • openmeter/currencies/adapter/currencies.go

Comment thread openmeter/currencies/adapter/currencies.go
Comment thread openmeter/currencies/adapter/currencies.go
Comment thread openmeter/currencies/adapter/currencies.go
@chrisgacsal
chrisgacsal enabled auto-merge (squash) July 22, 2026 19:59
@chrisgacsal
chrisgacsal merged commit da4b7ed into main Jul 22, 2026
27 checks passed
@chrisgacsal
chrisgacsal deleted the feat/currencies-list branch July 22, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants