Skip to content

Commit

Permalink
fix: ListInvoices fixes (#2120)
Browse files Browse the repository at this point in the history
  • Loading branch information
turip authored Jan 21, 2025
1 parent 2a7562e commit d7419c0
Show file tree
Hide file tree
Showing 10 changed files with 1,577 additions and 1,496 deletions.
1,500 changes: 757 additions & 743 deletions api/api.gen.go

Large diffs are not rendered by default.

1,529 changes: 776 additions & 753 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions api/client/node/schemas/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7346,6 +7346,8 @@ export interface components {
'InvoiceListParams.expand': components['schemas']['InvoiceExpand'][]
/** @description Filter by invoice extended statuses */
'InvoiceListParams.extendedStatuses': string[]
/** @description Include deleted invoices */
'InvoiceListParams.includeDeleted': boolean
/** @description Filter by invoice creation time */
'InvoiceListParams.issuedAfter': string
/** @description Filter by invoice creation time */
Expand Down Expand Up @@ -8421,6 +8423,8 @@ export interface operations {
expand?: components['parameters']['InvoiceListParams.expand']
/** @description Filter by customer ID */
customers?: components['parameters']['InvoiceListParams.customers']
/** @description Include deleted invoices */
includeDeleted?: components['parameters']['InvoiceListParams.includeDeleted']
/** @description Start date-time in RFC 3339 format.
*
* Inclusive. */
Expand Down
4 changes: 4 additions & 0 deletions api/client/web/src/client/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7355,6 +7355,8 @@ export interface components {
'InvoiceListParams.expand': components['schemas']['InvoiceExpand'][]
/** @description Filter by invoice extended statuses */
'InvoiceListParams.extendedStatuses': string[]
/** @description Include deleted invoices */
'InvoiceListParams.includeDeleted': boolean
/** @description Filter by invoice creation time */
'InvoiceListParams.issuedAfter': string
/** @description Filter by invoice creation time */
Expand Down Expand Up @@ -8430,6 +8432,8 @@ export interface operations {
expand?: components['parameters']['InvoiceListParams.expand']
/** @description Filter by customer ID */
customers?: components['parameters']['InvoiceListParams.customers']
/** @description Include deleted invoices */
includeDeleted?: components['parameters']['InvoiceListParams.includeDeleted']
/** @description Start date-time in RFC 3339 format.
*
* Inclusive. */
Expand Down
9 changes: 9 additions & 0 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ paths:
- $ref: '#/components/parameters/InvoiceListParams.issuedBefore'
- $ref: '#/components/parameters/InvoiceListParams.expand'
- $ref: '#/components/parameters/InvoiceListParams.customers'
- $ref: '#/components/parameters/InvoiceListParams.includeDeleted'
- $ref: '#/components/parameters/Pagination.page'
- $ref: '#/components/parameters/Pagination.pageSize'
- $ref: '#/components/parameters/LimitOffset.offset'
Expand Down Expand Up @@ -7599,6 +7600,14 @@ components:
items:
type: string
explode: false
InvoiceListParams.includeDeleted:
name: includeDeleted
in: query
required: false
description: Include deleted invoices
schema:
type: boolean
explode: false
InvoiceListParams.issuedAfter:
name: issuedAfter
in: query
Expand Down
9 changes: 9 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ paths:
- $ref: '#/components/parameters/InvoiceListParams.issuedBefore'
- $ref: '#/components/parameters/InvoiceListParams.expand'
- $ref: '#/components/parameters/InvoiceListParams.customers'
- $ref: '#/components/parameters/InvoiceListParams.includeDeleted'
- $ref: '#/components/parameters/Pagination.page'
- $ref: '#/components/parameters/Pagination.pageSize'
- $ref: '#/components/parameters/LimitOffset.offset'
Expand Down Expand Up @@ -7195,6 +7196,14 @@ components:
items:
type: string
explode: false
InvoiceListParams.includeDeleted:
name: includeDeleted
in: query
required: false
description: Include deleted invoices
schema:
type: boolean
explode: false
InvoiceListParams.issuedAfter:
name: issuedAfter
in: query
Expand Down
6 changes: 6 additions & 0 deletions api/spec/src/billing/invoices.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ model InvoiceListParams {
*/
@query
customers?: ULID[];

/**
* Include deleted invoices
*/
@query
includeDeleted?: boolean;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions openmeter/billing/adapter/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func (a *adapter) ListInvoices(ctx context.Context, input billing.ListInvoicesIn
query = query.Where(billinginvoice.IDIn(input.IDs...))
}

if !input.IncludeDeleted {
query = query.Where(billinginvoice.DeletedAtIsNil())
}

if len(input.Statuses) > 0 {
query = query.Where(func(s *sql.Selector) {
s.Where(sql.Or(
Expand Down
6 changes: 6 additions & 0 deletions openmeter/billing/httpdriver/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/openmeterio/openmeter/pkg/models"
"github.com/openmeterio/openmeter/pkg/pagination"
"github.com/openmeterio/openmeter/pkg/slicesx"
"github.com/openmeterio/openmeter/pkg/sortx"
)

var _ InvoiceHandler = (*handler)(nil)
Expand Down Expand Up @@ -60,6 +61,11 @@ func (h *handler) ListInvoices() ListInvoicesHandler {
IssuedBefore: input.IssuedBefore,
Expand: mapInvoiceExpandToEntity(lo.FromPtrOr(input.Expand, nil)).SetGatheringTotals(true),

Order: sortx.Order(lo.FromPtrOr(input.Order, api.InvoiceOrderByOrderingOrder(sortx.OrderDefault))),
OrderBy: lo.FromPtrOr(input.OrderBy, ""),

IncludeDeleted: lo.FromPtrOr(input.IncludeDeleted, false),

Page: pagination.Page{
PageSize: lo.FromPtrOr(input.PageSize, DefaultPageSize),
PageNumber: lo.FromPtrOr(input.Page, DefaultPageNumber),
Expand Down
2 changes: 2 additions & 0 deletions openmeter/billing/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ type ListInvoicesInput struct {
IssuedAfter *time.Time
IssuedBefore *time.Time

IncludeDeleted bool

// DraftUtil allows to filter invoices which have their draft state expired based on the provided time.
// Invoice is expired if the time defined by Invoice.DraftUntil is in the past compared to ListInvoicesInput.DraftUntil.
DraftUntil *time.Time
Expand Down

0 comments on commit d7419c0

Please sign in to comment.