File size: 1,822 Bytes
429334c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | package app
import (
"errors"
"fmt"
"github.com/openmeterio/openmeter/openmeter/customer"
"github.com/openmeterio/openmeter/pkg/models"
"github.com/openmeterio/openmeter/pkg/pagination"
)
type ListCustomerInput struct {
pagination.Page
AppID *AppID
CustomerID customer.CustomerID
Type *AppType
}
func (a ListCustomerInput) Validate() error {
var errs []error
if err := a.CustomerID.Validate(); err != nil {
errs = append(errs, err)
}
if a.AppID != nil {
if err := a.AppID.Validate(); err != nil {
errs = append(errs, err)
}
}
if a.Type != nil {
if *a.Type == "" {
errs = append(errs, models.NewGenericValidationError(
fmt.Errorf("app type cannot be empty"),
))
}
}
return errors.Join(errs...)
}
type EnsureCustomerInput struct {
AppID AppID
CustomerID customer.CustomerID
}
func (a EnsureCustomerInput) Validate() error {
if err := a.AppID.Validate(); err != nil {
return err
}
if err := a.CustomerID.Validate(); err != nil {
return err
}
if a.AppID.Namespace != a.CustomerID.Namespace {
return fmt.Errorf("app ID namespace %s does not match customer ID namespace %s", a.AppID.Namespace, a.CustomerID.Namespace)
}
return nil
}
type DeleteCustomerInput struct {
AppID *AppID
CustomerID *customer.CustomerID
}
func (a DeleteCustomerInput) Validate() error {
if a.AppID == nil && a.CustomerID == nil {
return fmt.Errorf("app ID and customer ID cannot be nil")
}
if a.AppID != nil {
if err := a.AppID.Validate(); err != nil {
return err
}
}
if a.CustomerID != nil {
if err := a.CustomerID.Validate(); err != nil {
return err
}
}
if a.AppID != nil && a.CustomerID != nil && a.AppID.Namespace != a.CustomerID.Namespace {
return errors.New("app and customer must be in the same namespace")
}
return nil
}
|