Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,748 changes: 876 additions & 872 deletions api/api.gen.go

Large diffs are not rendered by default.

1,696 changes: 850 additions & 846 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions api/client/javascript/src/client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3674,6 +3674,11 @@ export interface components {
* Only with the `subscriptions` expand option.
*/
readonly subscriptions?: components['schemas']['Subscription'][]
/**
* Annotations
* @description Set of key-value pairs managed by the system. Cannot be modified by user.
*/
readonly annotations?: components['schemas']['Annotations']
}
/** @description CustomerAccess describes what features the customer has access to. */
CustomerAccess: {
Expand Down
6 changes: 6 additions & 0 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13342,6 +13342,12 @@ components:
Only with the `subscriptions` expand option.
title: Subscriptions
readOnly: true
annotations:
allOf:
- $ref: '#/components/schemas/Annotations'
description: Set of key-value pairs managed by the system. Cannot be modified by user.
title: Annotations
readOnly: true
description: A customer object.
example:
id: 01G65Z755AFWAKHE12NY0CQ9FH
Expand Down
6 changes: 6 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13500,6 +13500,12 @@ components:
Only with the `subscriptions` expand option.
title: Subscriptions
readOnly: true
annotations:
allOf:
- $ref: '#/components/schemas/Annotations'
description: Set of key-value pairs managed by the system. Cannot be modified by user.
title: Annotations
readOnly: true
description: A customer object.
example:
id: 01G65Z755AFWAKHE12NY0CQ9FH
Expand Down
9 changes: 7 additions & 2 deletions api/spec/src/customer.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,17 @@ model Customer {
/**
* The subscriptions of the customer.
* Only with the `subscriptions` expand option.
*
* @visibility(Lifecycle.Read)
*/
@summary("Subscriptions")
@visibility(Lifecycle.Read)
subscriptions?: ProductCatalog.Subscription[];

/**
* Set of key-value pairs managed by the system. Cannot be modified by user.
*/
@summary("Annotations")
@visibility(Lifecycle.Read)
annotations?: Annotations;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions openmeter/customer/adapter/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func (a *adapter) CreateCustomer(ctx context.Context, input customer.CreateCusto
query = query.SetMetadata(input.Metadata.ToMap())
}

if input.Annotation != nil {
query = query.SetAnnotations(*input.Annotation)
}

if input.BillingAddress != nil {
query = query.
SetNillableBillingAddressCity(input.BillingAddress.City).
Expand Down Expand Up @@ -445,6 +449,12 @@ func (a *adapter) UpdateCustomer(ctx context.Context, input customer.UpdateCusto
query = query.ClearMetadata()
}

if input.Annotation != nil {
query = query.SetAnnotations(*input.Annotation)
} else {
query = query.ClearAnnotations()
}

if input.BillingAddress != nil {
query = query.
SetNillableBillingAddressCity(input.BillingAddress.City).
Expand Down
7 changes: 7 additions & 0 deletions openmeter/customer/adapter/entitymapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func CustomerFromDBEntity(e db.Customer) (*customer.Customer, error) {
metadata = lo.ToPtr(models.NewMetadata(e.Metadata))
}

var annotations *models.Annotations

if len(e.Annotations) > 0 {
annotations = lo.ToPtr(e.Annotations)
}

result := &customer.Customer{
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
ID: e.ID,
Expand All @@ -42,6 +48,7 @@ func CustomerFromDBEntity(e db.Customer) (*customer.Customer, error) {
PrimaryEmail: e.PrimaryEmail,
Currency: e.Currency,
Metadata: metadata,
Annotation: annotations,
}

if e.Key != "" {
Expand Down
2 changes: 2 additions & 0 deletions openmeter/customer/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Customer struct {
Currency *currencyx.Code `json:"currency,omitempty"`
BillingAddress *models.Address `json:"billingAddress,omitempty"`
Metadata *models.Metadata `json:"metadata,omitempty"`
Annotation *models.Annotations `json:"annotations,omitempty"`
}

func (c Customer) Validate() error {
Expand Down Expand Up @@ -53,6 +54,7 @@ type CustomerMutate struct {
Currency *currencyx.Code `json:"currency"`
BillingAddress *models.Address `json:"billingAddress"`
Metadata *models.Metadata `json:"metadata"`
Annotation *models.Annotations `json:"annotations,omitempty"`
}

func (c CustomerMutate) Validate() error {
Expand Down
38 changes: 32 additions & 6 deletions openmeter/customer/httpdriver/apimapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,38 @@ func MapAddress(apiAddress *api.Address) *models.Address {
return &address
}

// CustomerToAPI converts a Customer to an API Customer
func CustomerToAPI(c customer.Customer, subscriptions []subscription.Subscription, expand []api.CustomerExpand) (api.Customer, error) {
var metadata *api.Metadata
func FromMetadata(metadata models.Metadata) *api.Metadata {
if len(metadata) == 0 {
return nil
}

result := make(api.Metadata)
if len(metadata) > 0 {
for k, v := range metadata {
result[k] = v
}
}

if c.Metadata != nil {
metadata = lo.ToPtr(c.Metadata.ToMap())
return &result
}

func FromAnnotations(annotations models.Annotations) *api.Annotations {
if len(annotations) == 0 {
return nil
}

result := make(api.Annotations)
if len(annotations) > 0 {
for k, v := range annotations {
result[k] = v
}
}

return &result
}

// CustomerToAPI converts a Customer to an API Customer
func CustomerToAPI(c customer.Customer, subscriptions []subscription.Subscription, expand []api.CustomerExpand) (api.Customer, error) {
// Map the customer to the API Customer
apiCustomer := api.Customer{
Id: c.ManagedResource.ID,
Expand All @@ -97,7 +122,8 @@ func CustomerToAPI(c customer.Customer, subscriptions []subscription.Subscriptio
CreatedAt: c.CreatedAt,
UpdatedAt: c.UpdatedAt,
DeletedAt: c.DeletedAt,
Metadata: metadata,
Metadata: FromMetadata(lo.FromPtr(c.Metadata)),
Annotations: FromAnnotations(lo.FromPtr(c.Annotation)),
}

if c.BillingAddress != nil {
Expand Down
15 changes: 14 additions & 1 deletion openmeter/ent/db/customer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions openmeter/ent/db/customer/customer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions openmeter/ent/db/customer/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions openmeter/ent/db/customer_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading