refactor: currencies service pkg#4638
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
💤 Files with no reviewable changes (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (15)
📝 WalkthroughWalkthroughThe currencies package now uses split ChangesCurrencies domain, service, and handler refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
73d9a3c to
d953ff4
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
openmeter/currencies/service.go (1)
40-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winWrap these validators with
models.NewNillableGenericValidationError.
ListCurrenciesInput,CreateCurrencyInput,CreateCostBasisInput, andListCostBasesInputshould returnmodels.NewNillableGenericValidationError(errors.Join(errs...))instead of a rawerrors.Join(...).OrderBy.Validate()should use the same validation error type for the invalid case too.🤖 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/service.go` around lines 40 - 46, The validation paths are returning raw errors instead of the project’s nillable generic validation type. Update the validation logic in ListCurrenciesInput, CreateCurrencyInput, CreateCostBasisInput, and ListCostBasesInput so they wrap the joined validation errors with models.NewNillableGenericValidationError, and make OrderBy.Validate return that same error type for invalid values instead of a plain fmt.Errorf. Use the existing validation helpers and the OrderBy.Validate method as the main points to adjust.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.
Inline comments:
In `@openmeter/currencies/currency.go`:
- Around line 12-19: CurrencyType.Validate currently fails fast by returning a
plain fmt.Errorf in the default branch, but it should follow the project
validation pattern. Update Validate() to build a var errs []error, append the
invalid-type error when t is not CurrencyTypeCustom or CurrencyTypeFiat, and
return models.NewNillableGenericValidationError(errors.Join(errs...)) instead of
returning immediately.
In `@openmeter/currencies/service/service_test.go`:
- Around line 71-73: `New` now returns an error, so the test helper and any
other `New(...)` call sites in this file must be updated to handle the second
return value. In `newTestService`, create the service and error from
`New(&fakeAdapter{custom: custom})`, then assert the error is nil with
`require.NoError(t, err)` before returning the service; apply the same pattern
to the other `New` usages in this test file.
---
Nitpick comments:
In `@openmeter/currencies/service.go`:
- Around line 40-46: The validation paths are returning raw errors instead of
the project’s nillable generic validation type. Update the validation logic in
ListCurrenciesInput, CreateCurrencyInput, CreateCostBasisInput, and
ListCostBasesInput so they wrap the joined validation errors with
models.NewNillableGenericValidationError, and make OrderBy.Validate return that
same error type for invalid values instead of a plain fmt.Errorf. Use the
existing validation helpers and the OrderBy.Validate method as the main points
to adjust.
🪄 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: 5bfddfd7-8889-4a81-8fe8-5975ce6bd14a
📒 Files selected for processing (17)
api/v3/handlers/currencies/create.goapi/v3/handlers/currencies/create_cost_basis.goapi/v3/handlers/currencies/get_cost_bases.goapi/v3/handlers/currencies/handler.goapi/v3/handlers/currencies/list.goapp/common/currency.gocmd/server/wire.gocmd/server/wire_gen.goopenmeter/currencies/adapter/adapter.goopenmeter/currencies/adapter/currencies.goopenmeter/currencies/costbasis.goopenmeter/currencies/currency.goopenmeter/currencies/models.goopenmeter/currencies/repository.goopenmeter/currencies/service.goopenmeter/currencies/service/service.goopenmeter/currencies/service/service_test.go
💤 Files with no reviewable changes (2)
- openmeter/currencies/adapter/currencies.go
- openmeter/currencies/models.go
| func (t CurrencyType) Validate() error { | ||
| switch t { | ||
| case CurrencyTypeCustom, CurrencyTypeFiat: | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("currency type: %s", t) | ||
| } | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Validate() should collect errors, not fail fast.
As per coding guidelines, Go Validate() error methods should collect issues into var errs []error and return models.NewNillableGenericValidationError(errors.Join(errs...)) instead of failing fast. This switch-based implementation returns immediately on the first (and only) failure instead of following that convention.
♻️ Suggested fix
func (t CurrencyType) Validate() error {
- switch t {
- case CurrencyTypeCustom, CurrencyTypeFiat:
- return nil
- default:
- return fmt.Errorf("currency type: %s", t)
- }
+ var errs []error
+ switch t {
+ case CurrencyTypeCustom, CurrencyTypeFiat:
+ default:
+ errs = append(errs, fmt.Errorf("currency type: %s", t))
+ }
+ return models.NewNillableGenericValidationError(errors.Join(errs...))
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (t CurrencyType) Validate() error { | |
| switch t { | |
| case CurrencyTypeCustom, CurrencyTypeFiat: | |
| return nil | |
| default: | |
| return fmt.Errorf("currency type: %s", t) | |
| } | |
| } | |
| func (t CurrencyType) Validate() error { | |
| var errs []error | |
| switch t { | |
| case CurrencyTypeCustom, CurrencyTypeFiat: | |
| default: | |
| errs = append(errs, fmt.Errorf("currency type: %s", t)) | |
| } | |
| return models.NewNillableGenericValidationError(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/currency.go` around lines 12 - 19, CurrencyType.Validate
currently fails fast by returning a plain fmt.Errorf in the default branch, but
it should follow the project validation pattern. Update Validate() to build a
var errs []error, append the invalid-type error when t is not CurrencyTypeCustom
or CurrencyTypeFiat, and return
models.NewNillableGenericValidationError(errors.Join(errs...)) instead of
returning immediately.
Source: Coding guidelines
Greptile SummaryThis PR refactors the
Confidence Score: 5/5Safe to merge — purely a rename/restructure with no changes to business logic or database queries. All interface renames and constructor signature changes are consistently propagated across handlers, server configs, wire wiring, and tests. The only items left behind are two stale comments (one referencing the deleted
Important Files Changed
|
|
|
||
| func (t CurrencyType) Values() []CurrencyType { | ||
| return []CurrencyType{ | ||
| CurrencyTypeCustom, | ||
| CurrencyTypeFiat, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Values() method defined on value receiver with no reference to t
CurrencyType.Values() always returns the same static slice regardless of the receiver value. This is either a utility method that belongs at the package level (not on the type), or it should be a package-level var/func. Defining it as an instance method is misleading — it implies the returned values depend on the receiver, which they don't.
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/currencies/currency.go
Line: 20-27
Comment:
**`Values()` method defined on value receiver with no reference to `t`**
`CurrencyType.Values()` always returns the same static slice regardless of the receiver value. This is either a utility method that belongs at the package level (not on the type), or it should be a package-level `var`/`func`. Defining it as an instance method is misleading — it implies the returned values depend on the receiver, which they don't.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
d953ff4 to
965f005
Compare
Overview
Refactor
currenciesservice package to be more aligned with the project. No functional changes.Summary by CodeRabbit