Skip to content

Commit 4b30bd1

Browse files
committed
chore(api): export utility functions
1 parent 92d301c commit 4b30bd1

7 files changed

Lines changed: 95 additions & 95 deletions

File tree

api/v3/handlers/plans/convert.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func ToAPIBillingPlan(p plan.Plan) (api.BillingPlan, error) {
5555
UpdatedAt: lo.ToPtr(p.UpdatedAt),
5656
Version: p.Version,
5757
ProRatingEnabled: lo.ToPtr(p.ProRatingConfig.Enabled),
58-
ValidationErrors: toAPIProductCatalogValidationErrors(validationIssues),
58+
ValidationErrors: ToAPIProductCatalogValidationErrors(validationIssues),
5959
}
6060

6161
var status api.BillingPlanStatus
@@ -76,7 +76,7 @@ func ToAPIBillingPlan(p plan.Plan) (api.BillingPlan, error) {
7676

7777
resp.Phases = make([]api.BillingPlanPhase, 0, len(p.Phases))
7878
for _, phase := range p.Phases {
79-
billingPhase, err := toAPIBillingPlanPhase(phase)
79+
billingPhase, err := ToAPIBillingPlanPhase(phase)
8080
if err != nil {
8181
return resp, fmt.Errorf("failed to convert plan phase: %w", err)
8282
}
@@ -87,7 +87,7 @@ func ToAPIBillingPlan(p plan.Plan) (api.BillingPlan, error) {
8787
return resp, nil
8888
}
8989

90-
func toAPIBillingPlanPhase(p plan.Phase) (api.BillingPlanPhase, error) {
90+
func ToAPIBillingPlanPhase(p plan.Phase) (api.BillingPlanPhase, error) {
9191
phase := api.BillingPlanPhase{
9292
Description: p.Description,
9393
Duration: (*api.ISO8601Duration)(p.Duration.ISOStringPtrOrNil()),
@@ -97,7 +97,7 @@ func toAPIBillingPlanPhase(p plan.Phase) (api.BillingPlanPhase, error) {
9797
}
9898

9999
for _, rc := range p.RateCards {
100-
billingRC, err := toAPIBillingRateCard(rc)
100+
billingRC, err := ToAPIBillingRateCard(rc)
101101
if err != nil {
102102
return phase, fmt.Errorf("failed to convert rate card %q: %w", rc.Key(), err)
103103
}
@@ -108,15 +108,15 @@ func toAPIBillingPlanPhase(p plan.Phase) (api.BillingPlanPhase, error) {
108108
return phase, nil
109109
}
110110

111-
func toAPIBillingRateCard(rc productcatalog.RateCard) (api.BillingRateCard, error) {
111+
func ToAPIBillingRateCard(rc productcatalog.RateCard) (api.BillingRateCard, error) {
112112
meta := rc.AsMeta()
113113

114114
result := api.BillingRateCard{
115115
Key: meta.Key,
116116
Name: meta.Name,
117117
Description: meta.Description,
118-
Discounts: toAPIBillingRateCardDiscount(meta.Discounts),
119-
TaxConfig: toAPIBillingRateCardTaxConfi(meta.TaxConfig, meta.TaxCode),
118+
Discounts: ToAPIBillingRateCardDiscount(meta.Discounts),
119+
TaxConfig: ToAPIBillingRateCardTaxConfi(meta.TaxConfig, meta.TaxCode),
120120
}
121121

122122
if meta.FeatureID != nil {
@@ -149,14 +149,14 @@ func toAPIBillingRateCard(rc productcatalog.RateCard) (api.BillingRateCard, erro
149149
result.BillingCadence = lo.ToPtr(bc.ISOString().String())
150150

151151
if meta.Price != nil {
152-
result.Commitments = toAPIBillingSpendCommitments(meta.Price.GetCommitments())
152+
result.Commitments = ToAPIBillingSpendCommitments(meta.Price.GetCommitments())
153153
}
154154

155155
default:
156156
return result, fmt.Errorf("unknown rate card type: %s", rc.Type())
157157
}
158158

159-
price, err := toAPIBillingPrice(meta.Price)
159+
price, err := ToAPIBillingPrice(meta.Price)
160160
if err != nil {
161161
return result, fmt.Errorf("failed to convert price: %w", err)
162162
}
@@ -166,7 +166,7 @@ func toAPIBillingRateCard(rc productcatalog.RateCard) (api.BillingRateCard, erro
166166
return result, nil
167167
}
168168

169-
func toAPIBillingPrice(p *productcatalog.Price) (api.BillingPrice, error) {
169+
func ToAPIBillingPrice(p *productcatalog.Price) (api.BillingPrice, error) {
170170
var result api.BillingPrice
171171

172172
if p == nil {
@@ -212,7 +212,7 @@ func toAPIBillingPrice(p *productcatalog.Price) (api.BillingPrice, error) {
212212
return result, fmt.Errorf("failed to read tiered price: %w", err)
213213
}
214214

215-
tiers := toAPIBillingPriceTiers(tiered.Tiers)
215+
tiers := ToAPIBillingPriceTiers(tiered.Tiers)
216216

217217
switch tiered.Mode {
218218
case productcatalog.GraduatedTieredPrice:
@@ -248,7 +248,7 @@ func toAPIBillingPrice(p *productcatalog.Price) (api.BillingPrice, error) {
248248
return result, nil
249249
}
250250

251-
func toAPIBillingPriceTiers(tiers []productcatalog.PriceTier) []api.BillingPriceTier {
251+
func ToAPIBillingPriceTiers(tiers []productcatalog.PriceTier) []api.BillingPriceTier {
252252
result := make([]api.BillingPriceTier, 0, len(tiers))
253253

254254
for _, t := range tiers {
@@ -278,7 +278,7 @@ func toAPIBillingPriceTiers(tiers []productcatalog.PriceTier) []api.BillingPrice
278278
return result
279279
}
280280

281-
func toAPIBillingRateCardTaxConfi(c *productcatalog.TaxConfig, tc *taxcode.TaxCode) *api.BillingRateCardTaxConfig {
281+
func ToAPIBillingRateCardTaxConfi(c *productcatalog.TaxConfig, tc *taxcode.TaxCode) *api.BillingRateCardTaxConfig {
282282
if c == nil || tc == nil {
283283
return nil
284284
}
@@ -296,7 +296,7 @@ func toAPIBillingRateCardTaxConfi(c *productcatalog.TaxConfig, tc *taxcode.TaxCo
296296
return result
297297
}
298298

299-
func toAPIBillingRateCardDiscount(d productcatalog.Discounts) *api.BillingRateCardDiscounts {
299+
func ToAPIBillingRateCardDiscount(d productcatalog.Discounts) *api.BillingRateCardDiscounts {
300300
if d.Percentage == nil && d.Usage == nil {
301301
return nil
302302
}
@@ -315,7 +315,7 @@ func toAPIBillingRateCardDiscount(d productcatalog.Discounts) *api.BillingRateCa
315315
return result
316316
}
317317

318-
func toAPIBillingSpendCommitments(c productcatalog.Commitments) *api.BillingSpendCommitments {
318+
func ToAPIBillingSpendCommitments(c productcatalog.Commitments) *api.BillingSpendCommitments {
319319
if c.MinimumAmount == nil && c.MaximumAmount == nil {
320320
return nil
321321
}
@@ -333,7 +333,7 @@ func toAPIBillingSpendCommitments(c productcatalog.Commitments) *api.BillingSpen
333333
return result
334334
}
335335

336-
func toAPIProductCatalogValidationErrors(issues models.ValidationIssues) *[]api.ProductCatalogValidationError {
336+
func ToAPIProductCatalogValidationErrors(issues models.ValidationIssues) *[]api.ProductCatalogValidationError {
337337
if len(issues) == 0 {
338338
return nil
339339
}
@@ -358,7 +358,7 @@ func FromAPIUpsertPlanRequest(ns string, planID string, body api.UpsertPlanReque
358358
},
359359
Name: &body.Name,
360360
Description: body.Description,
361-
ProRatingConfig: lo.ToPtr(toProRatingConfig(body.ProRatingEnabled)),
361+
ProRatingConfig: lo.ToPtr(ToProRatingConfig(body.ProRatingEnabled)),
362362
}
363363

364364
meta, err := labels.ToMetadata(body.Labels)
@@ -373,7 +373,7 @@ func FromAPIUpsertPlanRequest(ns string, planID string, body api.UpsertPlanReque
373373

374374
phases := make([]productcatalog.Phase, 0, len(body.Phases))
375375
for _, phase := range body.Phases {
376-
p, err := fromAPIBillingPlanPhase(phase)
376+
p, err := FromAPIBillingPlanPhase(phase)
377377
if err != nil {
378378
return req, fmt.Errorf("failed to convert phase: %w", err)
379379
}
@@ -402,7 +402,7 @@ func FromAPICreatePlanRequest(ns string, body api.CreatePlanRequest) (plan.Creat
402402
Name: body.Name,
403403
Description: body.Description,
404404
Metadata: meta,
405-
ProRatingConfig: toProRatingConfig(body.ProRatingEnabled),
405+
ProRatingConfig: ToProRatingConfig(body.ProRatingEnabled),
406406
},
407407
},
408408
}
@@ -425,7 +425,7 @@ func FromAPICreatePlanRequest(ns string, body api.CreatePlanRequest) (plan.Creat
425425
req.Phases = make([]productcatalog.Phase, 0, len(body.Phases))
426426

427427
for _, phase := range body.Phases {
428-
p, err := fromAPIBillingPlanPhase(phase)
428+
p, err := FromAPIBillingPlanPhase(phase)
429429
if err != nil {
430430
return req, fmt.Errorf("failed to convert phase: %w", err)
431431
}
@@ -437,7 +437,7 @@ func FromAPICreatePlanRequest(ns string, body api.CreatePlanRequest) (plan.Creat
437437
return req, nil
438438
}
439439

440-
func toProRatingConfig(enabled *bool) productcatalog.ProRatingConfig {
440+
func ToProRatingConfig(enabled *bool) productcatalog.ProRatingConfig {
441441
if enabled == nil || *enabled {
442442
return productcatalog.ProRatingConfig{
443443
Enabled: true,
@@ -450,7 +450,7 @@ func toProRatingConfig(enabled *bool) productcatalog.ProRatingConfig {
450450
}
451451
}
452452

453-
func fromAPIBillingPlanPhase(p api.BillingPlanPhase) (productcatalog.Phase, error) {
453+
func FromAPIBillingPlanPhase(p api.BillingPlanPhase) (productcatalog.Phase, error) {
454454
meta, labelErr := labels.ToMetadata(p.Labels)
455455

456456
if labelErr != nil {
@@ -477,7 +477,7 @@ func fromAPIBillingPlanPhase(p api.BillingPlanPhase) (productcatalog.Phase, erro
477477
phase.RateCards = make(productcatalog.RateCards, 0, len(p.RateCards))
478478

479479
for _, rc := range p.RateCards {
480-
rateCard, err := fromAPIBillingRateCard(rc)
480+
rateCard, err := FromAPIBillingRateCard(rc)
481481
if err != nil {
482482
return phase, fmt.Errorf("failed to convert rate card %q: %w", rc.Key, err)
483483
}
@@ -489,7 +489,7 @@ func fromAPIBillingPlanPhase(p api.BillingPlanPhase) (productcatalog.Phase, erro
489489
return phase, nil
490490
}
491491

492-
func fromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, error) {
492+
func FromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, error) {
493493
priceType, err := rc.Price.Discriminator()
494494
if err != nil {
495495
return nil, fmt.Errorf("failed to read price type: %w", err)
@@ -512,11 +512,11 @@ func fromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, er
512512
}
513513

514514
if rc.TaxConfig != nil {
515-
meta.TaxConfig = fromAPIBillingRateCardTaxConfig(*rc.TaxConfig)
515+
meta.TaxConfig = FromAPIBillingRateCardTaxConfig(*rc.TaxConfig)
516516
}
517517

518518
if rc.Discounts != nil {
519-
discounts, err := fromAPIBillingRateCardDiscounts(*rc.Discounts)
519+
discounts, err := FromAPIBillingRateCardDiscounts(*rc.Discounts)
520520
if err != nil {
521521
return nil, fmt.Errorf("failed to convert discounts: %w", err)
522522
}
@@ -526,7 +526,7 @@ func fromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, er
526526

527527
switch priceType {
528528
case "free", "flat":
529-
price, err := fromAPIBillingPrice(rc.Price, rc.PaymentTerm)
529+
price, err := FromAPIBillingPrice(rc.Price, rc.PaymentTerm)
530530
if err != nil {
531531
return nil, fmt.Errorf("failed to convert price: %w", err)
532532
}
@@ -558,7 +558,7 @@ func fromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, er
558558
return nil, fmt.Errorf("invalid billing cadence: %w", err)
559559
}
560560

561-
price, err := fromAPIBillingPriceWithCommitments(rc.Price, rc.Commitments)
561+
price, err := FromAPIBillingPriceWithCommitments(rc.Price, rc.Commitments)
562562
if err != nil {
563563
return nil, fmt.Errorf("failed to convert price: %w", err)
564564
}
@@ -575,7 +575,7 @@ func fromAPIBillingRateCard(rc api.BillingRateCard) (productcatalog.RateCard, er
575575
}
576576
}
577577

578-
func fromAPIBillingPrice(p api.BillingPrice, paymentTerm *api.BillingPricePaymentTerm) (*productcatalog.Price, error) {
578+
func FromAPIBillingPrice(p api.BillingPrice, paymentTerm *api.BillingPricePaymentTerm) (*productcatalog.Price, error) {
579579
disc, err := p.Discriminator()
580580
if err != nil {
581581
return nil, fmt.Errorf("failed to read price type: %w", err)
@@ -611,13 +611,13 @@ func fromAPIBillingPrice(p api.BillingPrice, paymentTerm *api.BillingPricePaymen
611611
}
612612
}
613613

614-
func fromAPIBillingPriceWithCommitments(p api.BillingPrice, commitments *api.BillingSpendCommitments) (*productcatalog.Price, error) {
614+
func FromAPIBillingPriceWithCommitments(p api.BillingPrice, commitments *api.BillingSpendCommitments) (*productcatalog.Price, error) {
615615
disc, err := p.Discriminator()
616616
if err != nil {
617617
return nil, fmt.Errorf("failed to read price type: %w", err)
618618
}
619619

620-
c, err := parseCommitments(commitments)
620+
c, err := ParseCommitments(commitments)
621621
if err != nil {
622622
return nil, err
623623
}
@@ -645,7 +645,7 @@ func fromAPIBillingPriceWithCommitments(p api.BillingPrice, commitments *api.Bil
645645
return nil, fmt.Errorf("failed to read graduated price: %w", err)
646646
}
647647

648-
tiers, err := fromAPIBillingPriceTiers(grad.Tiers)
648+
tiers, err := FromAPIBillingPriceTiers(grad.Tiers)
649649
if err != nil {
650650
return nil, fmt.Errorf("failed to convert graduated tiers: %w", err)
651651
}
@@ -662,7 +662,7 @@ func fromAPIBillingPriceWithCommitments(p api.BillingPrice, commitments *api.Bil
662662
return nil, fmt.Errorf("failed to read volume price: %w", err)
663663
}
664664

665-
tiers, err := fromAPIBillingPriceTiers(vol.Tiers)
665+
tiers, err := FromAPIBillingPriceTiers(vol.Tiers)
666666
if err != nil {
667667
return nil, fmt.Errorf("failed to convert volume tiers: %w", err)
668668
}
@@ -678,7 +678,7 @@ func fromAPIBillingPriceWithCommitments(p api.BillingPrice, commitments *api.Bil
678678
}
679679
}
680680

681-
func parseCommitments(c *api.BillingSpendCommitments) (productcatalog.Commitments, error) {
681+
func ParseCommitments(c *api.BillingSpendCommitments) (productcatalog.Commitments, error) {
682682
if c == nil {
683683
return productcatalog.Commitments{}, nil
684684
}
@@ -706,7 +706,7 @@ func parseCommitments(c *api.BillingSpendCommitments) (productcatalog.Commitment
706706
return result, nil
707707
}
708708

709-
func fromAPIBillingPriceTiers(tiers []api.BillingPriceTier) ([]productcatalog.PriceTier, error) {
709+
func FromAPIBillingPriceTiers(tiers []api.BillingPriceTier) ([]productcatalog.PriceTier, error) {
710710
result := make([]productcatalog.PriceTier, 0, len(tiers))
711711

712712
for _, t := range tiers {
@@ -745,7 +745,7 @@ func fromAPIBillingPriceTiers(tiers []api.BillingPriceTier) ([]productcatalog.Pr
745745
return result, nil
746746
}
747747

748-
func fromAPIBillingRateCardTaxConfig(tc api.BillingRateCardTaxConfig) *productcatalog.TaxConfig {
748+
func FromAPIBillingRateCardTaxConfig(tc api.BillingRateCardTaxConfig) *productcatalog.TaxConfig {
749749
result := &productcatalog.TaxConfig{
750750
TaxCodeID: &tc.Code.Id,
751751
}
@@ -757,7 +757,7 @@ func fromAPIBillingRateCardTaxConfig(tc api.BillingRateCardTaxConfig) *productca
757757
return result
758758
}
759759

760-
func fromAPIBillingRateCardDiscounts(d api.BillingRateCardDiscounts) (productcatalog.Discounts, error) {
760+
func FromAPIBillingRateCardDiscounts(d api.BillingRateCardDiscounts) (productcatalog.Discounts, error) {
761761
result := productcatalog.Discounts{}
762762

763763
if d.Percentage != nil {

0 commit comments

Comments
 (0)