Skip to content

Commit 607e22e

Browse files
committed
feat: rename to UpcomingCharges
1 parent ba07cfb commit 607e22e

22 files changed

Lines changed: 223 additions & 231 deletions

openmeter/billing/adapter/gatheringinvoice.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (a *adapter) CreateGatheringInvoice(ctx context.Context, input billing.Crea
4040
workflowConfig := mapWorkflowConfigToDB(input.MergedProfile.WorkflowConfig, clonedWorkflowConfig.ID)
4141

4242
// Force cloning of the workflow
43-
// TODO: Is this needed?
4443
workflowConfig.ID = ""
4544

4645
currentSchemaLevel, err := tx.GetInvoiceDefaultSchemaLevel(ctx)
@@ -181,7 +180,7 @@ func (a *adapter) UpdateGatheringInvoice(ctx context.Context, in billing.Gatheri
181180
}
182181

183182
if in.Lines.IsPresent() {
184-
err := tx.updateGatheringLines(ctx, in.Lines.OrEmpty())
183+
err := tx.updateUpcomingCharges(ctx, in.Lines.OrEmpty())
185184
if err != nil {
186185
return err
187186
}
@@ -372,8 +371,8 @@ func (a *adapter) mapGatheringInvoiceFromDB(ctx context.Context, invoice *db.Bil
372371
Namespace: invoice.Namespace,
373372
},
374373
ManagedModel: models.ManagedModel{
375-
CreatedAt: invoice.CreatedAt,
376-
UpdatedAt: invoice.UpdatedAt,
374+
CreatedAt: invoice.CreatedAt.In(time.UTC),
375+
UpdatedAt: invoice.UpdatedAt.In(time.UTC),
377376
DeletedAt: convert.TimePtrIn(invoice.DeletedAt, time.UTC),
378377
},
379378
ID: invoice.ID,
@@ -403,7 +402,7 @@ func (a *adapter) mapGatheringInvoiceFromDB(ctx context.Context, invoice *db.Bil
403402
// return billing.StandardInvoice{}, err
404403
// }
405404

406-
res.Lines = billing.NewGatheringInvoiceLines(mappedLines)
405+
res.Lines = billing.NewGatheringInvoiceUpcomingCharges(mappedLines)
407406
}
408407

409408
return res, nil

openmeter/billing/adapter/gatheringlines.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ import (
2323
)
2424

2525
type gatheringLineDiff struct {
26-
Line entitydiff.Diff[*billing.GatheringLine]
26+
Line entitydiff.Diff[*billing.UpcomingCharge]
2727
}
2828

29-
func diffGatheringInvoiceLines(lines billing.GatheringLines) (gatheringLineDiff, error) {
30-
dbState := []*billing.GatheringLine{}
29+
func diffGatheringInvoiceLines(lines billing.UpcomingCharges) (gatheringLineDiff, error) {
30+
dbState := []*billing.UpcomingCharge{}
3131
for _, line := range lines {
3232
if line.DBState != nil {
3333
dbState = append(dbState, line.DBState)
3434
}
3535
}
3636

37-
linePtrs := lo.Map(lines, func(_ billing.GatheringLine, idx int) *billing.GatheringLine {
37+
linePtrs := lo.Map(lines, func(_ billing.UpcomingCharge, idx int) *billing.UpcomingCharge {
3838
return &lines[idx]
3939
})
4040

4141
diff := gatheringLineDiff{}
4242

43-
err := entitydiff.DiffByID(entitydiff.DiffByIDInput[*billing.GatheringLine]{
43+
err := entitydiff.DiffByID(entitydiff.DiffByIDInput[*billing.UpcomingCharge]{
4444
DBState: dbState,
4545
ExpectedState: linePtrs,
46-
HandleDelete: func(item *billing.GatheringLine) error {
46+
HandleDelete: func(item *billing.UpcomingCharge) error {
4747
diff.Line.NeedsDelete(item)
4848
return nil
4949
},
50-
HandleCreate: func(item *billing.GatheringLine) error {
50+
HandleCreate: func(item *billing.UpcomingCharge) error {
5151
diff.Line.NeedsCreate(item)
5252
return nil
5353
},
54-
HandleUpdate: func(item entitydiff.DiffUpdate[*billing.GatheringLine]) error {
54+
HandleUpdate: func(item entitydiff.DiffUpdate[*billing.UpcomingCharge]) error {
5555
diff.Line.NeedsUpdate(item)
5656
return nil
5757
},
@@ -63,14 +63,14 @@ func diffGatheringInvoiceLines(lines billing.GatheringLines) (gatheringLineDiff,
6363
return diff, nil
6464
}
6565

66-
func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.GatheringLines) error {
66+
func (a *adapter) updateUpcomingCharges(ctx context.Context, lines billing.UpcomingCharges) error {
6767
diff, err := diffGatheringInvoiceLines(lines)
6868
if err != nil {
6969
return err
7070
}
7171

72-
err = upsertWithOptions(ctx, a.db, diff.Line, upsertInput[*billing.GatheringLine, *db.BillingInvoiceUsageBasedLineConfigCreate]{
73-
Create: func(tx *db.Client, line *billing.GatheringLine) (*db.BillingInvoiceUsageBasedLineConfigCreate, error) {
72+
err = upsertWithOptions(ctx, a.db, diff.Line, upsertInput[*billing.UpcomingCharge, *db.BillingInvoiceUsageBasedLineConfigCreate]{
73+
Create: func(tx *db.Client, line *billing.UpcomingCharge) (*db.BillingInvoiceUsageBasedLineConfigCreate, error) {
7474
if line.UBPConfigID == "" {
7575
line.UBPConfigID = ulid.Make().String()
7676
}
@@ -97,8 +97,8 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
9797
return fmt.Errorf("creating usage based line configs: %w", err)
9898
}
9999

100-
invoiceLineUpsertConfig := upsertInput[*billing.GatheringLine, *db.BillingInvoiceLineCreate]{
101-
Create: func(tx *db.Client, line *billing.GatheringLine) (*db.BillingInvoiceLineCreate, error) {
100+
invoiceLineUpsertConfig := upsertInput[*billing.UpcomingCharge, *db.BillingInvoiceLineCreate]{
101+
Create: func(tx *db.Client, line *billing.UpcomingCharge) (*db.BillingInvoiceLineCreate, error) {
102102
if line.ID == "" {
103103
line.ID = ulid.Make().String()
104104
}
@@ -162,7 +162,7 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
162162
UpdateChildUniqueReferenceID().
163163
Exec(ctx)
164164
},
165-
MarkDeleted: func(ctx context.Context, line *billing.GatheringLine) (*billing.GatheringLine, error) {
165+
MarkDeleted: func(ctx context.Context, line *billing.UpcomingCharge) (*billing.UpcomingCharge, error) {
166166
line.DeletedAt = lo.ToPtr(clock.Now().In(time.UTC))
167167
return line, nil
168168
},
@@ -175,24 +175,24 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
175175
return nil
176176
}
177177

178-
func (a *adapter) mapGatheringInvoiceLinesFromDB(schemaLevel int, dbLines []*db.BillingInvoiceLine) ([]billing.GatheringLine, error) {
179-
return slicesx.MapWithErr(dbLines, func(dbLine *db.BillingInvoiceLine) (billing.GatheringLine, error) {
178+
func (a *adapter) mapGatheringInvoiceLinesFromDB(schemaLevel int, dbLines []*db.BillingInvoiceLine) ([]billing.UpcomingCharge, error) {
179+
return slicesx.MapWithErr(dbLines, func(dbLine *db.BillingInvoiceLine) (billing.UpcomingCharge, error) {
180180
return a.mapGatheringInvoiceLineFromDB(schemaLevel, dbLine)
181181
})
182182
}
183183

184-
func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.BillingInvoiceLine) (billing.GatheringLine, error) {
184+
func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.BillingInvoiceLine) (billing.UpcomingCharge, error) {
185185
if dbLine.Type != billing.InvoiceLineTypeUsageBased {
186-
return billing.GatheringLine{}, fmt.Errorf("only usage based lines can be gathering invoice lines [line_id=%s]", dbLine.ID)
186+
return billing.UpcomingCharge{}, fmt.Errorf("only usage based lines can be gathering invoice lines [line_id=%s]", dbLine.ID)
187187
}
188188

189189
ubpLine := dbLine.Edges.UsageBasedLine
190190
if ubpLine == nil {
191-
return billing.GatheringLine{}, fmt.Errorf("usage based line data is missing [line_id=%s]", dbLine.ID)
191+
return billing.UpcomingCharge{}, fmt.Errorf("usage based line data is missing [line_id=%s]", dbLine.ID)
192192
}
193193

194-
line := billing.GatheringLine{
195-
GatheringLineBase: billing.GatheringLineBase{
194+
line := billing.UpcomingCharge{
195+
UpcomingChargeBase: billing.UpcomingChargeBase{
196196
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
197197
Namespace: dbLine.Namespace,
198198
ID: dbLine.ID,
@@ -243,7 +243,7 @@ func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.Bill
243243

244244
cloned, err := line.WithoutDBState()
245245
if err != nil {
246-
return billing.GatheringLine{}, fmt.Errorf("cloning line: %w", err)
246+
return billing.UpcomingCharge{}, fmt.Errorf("cloning line: %w", err)
247247
}
248248

249249
line.DBState = lo.ToPtr(cloned)

0 commit comments

Comments
 (0)