feat(taxcode): add organization default tax codes HTTP handlers#4320
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 (6)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR wires up two HTTP endpoints for managing organization default tax codes. It adds conversion helpers to translate between API tax code references and internal ID strings, generates bidirectional converters using goverter, implements GET and UPSERT handlers that coordinate with the service layer, and connects both endpoints to their route handlers. ChangesOrganization Default Tax Codes API Implementation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
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 docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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: 1
🧹 Nitpick comments (1)
api/v3/handlers/taxcodes/convert.go (1)
101-113: 💤 Low valueEasy DRY win: shared private helper for the reference converters.
InvoicingTaxCodeReferenceToIDStringandCreditGrantTaxCodeReferenceToIDStringare character-for-character identical except for the error string. A small private helper cleans this up nicely.♻️ Proposed refactor
+func taxCodeReferenceToIDString(ref *api.TaxCodeReference, field string) (string, error) { + if ref == nil || ref.Id == "" { + return "", models.NewGenericValidationError(fmt.Errorf("%s is required", field)) + } + return ref.Id, nil +} + func InvoicingTaxCodeReferenceToIDString(ref *api.TaxCodeReference) (string, error) { - if ref == nil || ref.Id == "" { - return "", models.NewGenericValidationError(errors.New("invoicing_tax_code.id is required")) - } - return ref.Id, nil + return taxCodeReferenceToIDString(ref, "invoicing_tax_code.id") } func CreditGrantTaxCodeReferenceToIDString(ref *api.TaxCodeReference) (string, error) { - if ref == nil || ref.Id == "" { - return "", models.NewGenericValidationError(errors.New("credit_grant_tax_code.id is required")) - } - return ref.Id, nil + return taxCodeReferenceToIDString(ref, "credit_grant_tax_code.id") }(You'd swap
errors.Newforfmt.Errorf, or keep theerrorsimport and useerrors.New(field + " is required")— whatever style fits the file best.)🤖 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/taxcodes/convert.go` around lines 101 - 113, The two functions InvoicingTaxCodeReferenceToIDString and CreditGrantTaxCodeReferenceToIDString are identical except for the error message; create a small private helper (e.g., taxCodeRefToIDString(ref *api.TaxCodeReference, fieldName string) (string, error)) that checks ref and ref.Id and returns the id or a models.NewGenericValidationError with a constructed message like "<fieldName> is required", then replace both InvoicingTaxCodeReferenceToIDString and CreditGrantTaxCodeReferenceToIDString to call this helper with the appropriate field name; use fmt.Errorf or errors.New for building the message consistent with the file's imports.
🤖 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/v3/handlers/taxcodes/upsert_organization_default_tax_codes.go`:
- Around line 3-13: The import block in upsert_organization_default_tax_codes.go
is misordered causing gci formatting errors; run the project's import formatter
(e.g., gci write on this file or the repo make target that formats imports) to
reorder/group imports correctly so the file passes CI. Ensure the imports around
symbols context, net/http, api (github.com/openmeterio/openmeter/api/v3),
apierrors, request, taxcode, commonhttp, and httptransport are formatted by the
tool and then commit the updated file.
---
Nitpick comments:
In `@api/v3/handlers/taxcodes/convert.go`:
- Around line 101-113: The two functions InvoicingTaxCodeReferenceToIDString and
CreditGrantTaxCodeReferenceToIDString are identical except for the error
message; create a small private helper (e.g., taxCodeRefToIDString(ref
*api.TaxCodeReference, fieldName string) (string, error)) that checks ref and
ref.Id and returns the id or a models.NewGenericValidationError with a
constructed message like "<fieldName> is required", then replace both
InvoicingTaxCodeReferenceToIDString and CreditGrantTaxCodeReferenceToIDString to
call this helper with the appropriate field name; use fmt.Errorf or errors.New
for building the message consistent with the file's imports.
🪄 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: 8eb19632-eedb-4b9b-ac67-bef43cd016c4
📒 Files selected for processing (6)
api/v3/handlers/taxcodes/convert.gen.goapi/v3/handlers/taxcodes/convert.goapi/v3/handlers/taxcodes/get_organization_default_tax_codes.goapi/v3/handlers/taxcodes/handler.goapi/v3/handlers/taxcodes/upsert_organization_default_tax_codes.goapi/v3/server/routes.go
df81cec to
1682b2c
Compare
1682b2c to
7398e04
Compare
@coderabbitai
Summary by CodeRabbit
New Features