Repository navigation
feat: add planaddon service implementation - #2681
Conversation
📝 WalkthroughWalkthroughThis change introduces a new service layer for managing plan add-ons in a product catalog system. It adds service methods for listing, creating, updating, retrieving, and deleting plan add-on assignments, with comprehensive input validation, error handling, and event publishing. The service is constructed with explicit dependencies and validated for correct setup. Tests are added to cover the full lifecycle of plan add-on assignments, ensuring correct CRUD behavior and integration with related entities. Additionally, error messages in the adapter are improved for better context. Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
openmeter/productcatalog/planaddon/adapter/planaddon.go (1)
364-364: Consider adding parameter context to align with other error messages.
While the updated message is simpler, you might consider appending[namespace=%s plan.id=%s addon.id=%s]for consistency across the codebase. This is optional but helps unify error reporting.return nil, fmt.Errorf("failed to get plan add-on assignment for update: %w", err) +// Optional improvement: +// return nil, fmt.Errorf("failed to get plan add-on assignment for update [namespace=%s plan.id=%s addon.id=%s]: %w", +// params.Namespace, params.PlanID, params.AddonID, err)openmeter/productcatalog/planaddon/service/service_test.go (1)
1-471: Comprehensive test coverage.
The test suite thoroughly exercises create, retrieve, list, update, and delete flows, including published plan and add-on scenarios with multiphase environment setups. This ensures robust end-to-end validation.
Consider splitting some sub-tests into smaller, table-driven patterns for readability, but overall this is solid coverage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
openmeter/productcatalog/planaddon/adapter/planaddon.go(2 hunks)openmeter/productcatalog/planaddon/service/planaddon.go(1 hunks)openmeter/productcatalog/planaddon/service/service.go(1 hunks)openmeter/productcatalog/planaddon/service/service_test.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
openmeter/productcatalog/planaddon/service/service.go (1)
openmeter/watermill/eventbus/eventbus.go (1)
Publisher(61-73)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: CI
- GitHub Check: Analyze (go)
🔇 Additional comments (10)
openmeter/productcatalog/planaddon/adapter/planaddon.go (1)
167-168: Great job providing detailed context in the error message.
This improvement clarifies the offending parameters, making debugging easier. No further issues here.openmeter/productcatalog/planaddon/service/service.go (4)
13-19: Struct fields provide necessary dependencies for the new service.
This is a clean design that ensures all required references are centralized for easy usage.
21-49: Dependency validation ensures robust initialization.
Returning errors for nil dependencies prevents runtime issues. This is best practice for service constructors.
51-51: Nice compile-time interface check.
Verifying(*service)(nil)implementsplanaddon.Serviceprevents regressions if the service methods change.
53-59: Internal service struct is logically organized.
This struct neatly encapsulates references like adapter, plan, logger, and publisher. No concerns here.openmeter/productcatalog/planaddon/service/planaddon.go (5)
19-29: Straightforward delegation to the adapter.
Input validation and direct call tos.adapter.ListPlanAddons. This method is concise and meets the service contract.
31-135: Robust creation flow with pre-checks and event publishing.
- Good usage of a transaction to maintain data integrity.
- The conflict check ensures there's only one plan add-on assignment.
- Logging statements are well placed for traceability.
137-208: Soft delete implementation is consistent with typical domain logic.
- Validates the existence of the plan add-on first, returning early if it's already deleted.
- Publishes a delete event, facilitating asynchronous consumption in external systems.
210-243: Well-structured retrieval logic with consistent error handling.
- Logging is descriptive, including plan/add-on specifics.
- It properly transforms not found errors into a generic type.
245-352: Clear update flow with concurrency-safe approach.
- Quickly fetches the existing record and re-checks plan/add-on references to ensure valid state.
- Transaction usage is correct for atomic updates.
- Publishes an update event for external consumers.
Overview
Add implementation for plan add-on assignment service.
Summary by CodeRabbit