Skip to content

Commit d49b6cd

Browse files
committed
refactor(taxcode): rename plan validator hook to plan hook
1 parent 1603ab5 commit d49b6cd

5 files changed

Lines changed: 27 additions & 27 deletions

File tree

app/common/taxcode.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ func NewTaxCodeService(
4545
})
4646
}
4747

48-
// TaxCodePlanValidatorHook prevents deleting tax codes that are still referenced by plans.
49-
type TaxCodePlanValidatorHook taxcodehooks.PlanValidatorHook
48+
// TaxCodePlanHook prevents deleting tax codes that are still referenced by plans.
49+
type TaxCodePlanHook taxcodehooks.PlanHook
5050

51-
// NewTaxCodePlanValidatorServiceHook builds the plan-reference validator hook and registers it
51+
// NewTaxCodePlanServiceHook builds the plan-reference hook and registers it
5252
// on the tax code service. It depends on both the plan and tax code services so wire constructs
5353
// it only after both exist, avoiding a construction cycle (plan already depends on tax code).
54-
func NewTaxCodePlanValidatorServiceHook(
54+
func NewTaxCodePlanServiceHook(
5555
planService plan.Service,
5656
taxCodeService taxcode.Service,
57-
) (TaxCodePlanValidatorHook, error) {
58-
h, err := taxcodehooks.NewPlanValidatorHook(taxcodehooks.PlanValidatorHookConfig{
57+
) (TaxCodePlanHook, error) {
58+
h, err := taxcodehooks.NewPlanHook(taxcodehooks.PlanHookConfig{
5959
PlanService: planService,
6060
})
6161
if err != nil {
62-
return nil, fmt.Errorf("failed to create tax code plan validator hook: %w", err)
62+
return nil, fmt.Errorf("failed to create tax code plan hook: %w", err)
6363
}
6464

6565
taxCodeService.RegisterHooks(h)

cmd/server/wire.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type Application struct {
9999
StreamingConnector streaming.Connector
100100
TaxCodeNamespaceHandler *taxcode.NamespaceHandler
101101
TaxCodeService taxcode.Service
102-
TaxCodePlanValidatorHook common.TaxCodePlanValidatorHook
102+
TaxCodePlanHook common.TaxCodePlanHook
103103
TelemetryServer common.TelemetryServer
104104
TerminationChecker *common.TerminationChecker
105105
RuntimeMetricsCollector common.RuntimeMetricsCollector
@@ -149,7 +149,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration) (Appl
149149
common.Server,
150150
common.TaxCode,
151151
common.TaxCodeNamespaceHandler,
152-
common.NewTaxCodePlanValidatorServiceHook,
152+
common.NewTaxCodePlanServiceHook,
153153
common.Subscription,
154154
common.Lockr,
155155
common.Secret,

cmd/server/wire_gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/taxcode/service/hooks/planvalidator.go renamed to openmeter/taxcode/service/hooks/planhook.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@ import (
1515
)
1616

1717
type (
18-
PlanValidatorHook = models.ServiceHook[taxcode.TaxCode]
19-
NoopPlanValidatorHook = models.NoopServiceHook[taxcode.TaxCode]
18+
PlanHook = models.ServiceHook[taxcode.TaxCode]
19+
NoopPlanHook = models.NoopServiceHook[taxcode.TaxCode]
2020
)
2121

22-
type PlanValidatorHookConfig struct {
22+
type PlanHookConfig struct {
2323
PlanService plan.Service
2424
}
2525

26-
func (e PlanValidatorHookConfig) Validate() error {
26+
func (e PlanHookConfig) Validate() error {
2727
if e.PlanService == nil {
2828
return fmt.Errorf("plan service is required")
2929
}
3030

3131
return nil
3232
}
3333

34-
var _ models.ServiceHook[taxcode.TaxCode] = (*planValidatorHook)(nil)
34+
var _ models.ServiceHook[taxcode.TaxCode] = (*planHook)(nil)
3535

36-
type planValidatorHook struct {
37-
NoopPlanValidatorHook
36+
type planHook struct {
37+
NoopPlanHook
3838

3939
planService plan.Service
4040
}
4141

42-
func NewPlanValidatorHook(config PlanValidatorHookConfig) (PlanValidatorHook, error) {
42+
func NewPlanHook(config PlanHookConfig) (PlanHook, error) {
4343
if err := config.Validate(); err != nil {
44-
return nil, fmt.Errorf("invalid plan validator hook config: %w", err)
44+
return nil, fmt.Errorf("invalid plan hook config: %w", err)
4545
}
4646

47-
return &planValidatorHook{
47+
return &planHook{
4848
planService: config.PlanService,
4949
}, nil
5050
}
5151

52-
func (e *planValidatorHook) PreDelete(ctx context.Context, tc *taxcode.TaxCode) error {
52+
func (e *planHook) PreDelete(ctx context.Context, tc *taxcode.TaxCode) error {
5353
affectedPlans, err := e.planService.ListPlans(ctx, plan.ListPlansInput{
5454
Status: []productcatalog.PlanStatus{
5555
productcatalog.PlanStatusActive,

openmeter/taxcode/service/hooks/planvalidator_test.go renamed to openmeter/taxcode/service/hooks/planhook_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/openmeterio/openmeter/pkg/pagination"
1414
)
1515

16-
// stubPlanService implements plan.Service for testing the plan validator hook.
16+
// stubPlanService implements plan.Service for testing the plan hook.
1717
// Only ListPlans has real behavior; all other methods panic.
1818
type stubPlanService struct {
1919
listResult pagination.Result[plan.Plan]
@@ -58,7 +58,7 @@ var _ plan.Service = (*stubPlanService)(nil)
5858

5959
const testTaxCodeID = "01234567890123456789012345"
6060

61-
func TestPlanValidatorHook_PreDelete(t *testing.T) {
61+
func TestPlanHook_PreDelete(t *testing.T) {
6262
tc := &taxcode.TaxCode{
6363
NamespacedID: models.NamespacedID{
6464
Namespace: "test-ns",
@@ -77,7 +77,7 @@ func TestPlanValidatorHook_PreDelete(t *testing.T) {
7777
},
7878
}
7979

80-
hook, err := hooks.NewPlanValidatorHook(hooks.PlanValidatorHookConfig{PlanService: stub})
80+
hook, err := hooks.NewPlanHook(hooks.PlanHookConfig{PlanService: stub})
8181
require.NoError(t, err)
8282

8383
// when: PreDelete is called
@@ -103,7 +103,7 @@ func TestPlanValidatorHook_PreDelete(t *testing.T) {
103103
},
104104
}
105105

106-
hook, err := hooks.NewPlanValidatorHook(hooks.PlanValidatorHookConfig{PlanService: stub})
106+
hook, err := hooks.NewPlanHook(hooks.PlanHookConfig{PlanService: stub})
107107
require.NoError(t, err)
108108

109109
// when: PreDelete is called

0 commit comments

Comments
 (0)